DescriptionDescribe
His Royal Highness King of Berland Berl XV is a very wise man and had a very accomplished wife, who was aware of the fact , that prominent and outstanding personalities once have written down their names on the pages of glorious history, Rema In there forever. His Royal Highness King Berl XV experienced a intrinsic, lost nowadays, deep and sincere sense of respect and trust for H is beloved spouse. So he decided to acquire a chronicler of his own. Due to the ambiguous nature of misunderstanding and the crying injustice of history to ambiguity, he decided to leave all His royal responsibilities aside and made up he royal mind to find the chronicler, who would make him famous, depicting Al L His heroic deeds truthfully and gloriously enough.
Berland Berl XV The King is a very intelligent man, and has a superb wife. She was aware of the fact that only those who once had a very prominent personality would be able to write down their names in the glorious history and to be remembered. The King of Berland Berl XV had always had a deep and sincere respect and the trust of his wife, but it was now lost. So he decided to write a chronicle of his own. Because of the ambiguity of the misunderstanding and the ambiguous and unjust history, he decided to put all his royal duties behind him and decided to write the Chronicle, which would make him famous, true and glorious, depicting all his heroic deeds.
The King assembled the greatest minds of his kingdom at the academic chroniclers meeting (ACM), as he named it, and decide D to test their might. The task is to build the smallest lexicographical concatenation (SLC) out of the given N strings. SLC of N strings S1,..., SN is the lexicographically smallest their concatenation Si1 + ... + siN, where I1,..., in is a PE Rmutation of integers from 1 through N. It's a great privilege to being a chronicler, so don ' t miss your chance and don ' t screw it up! Make the King choose you!
His Royal Highness organized his country's biggest mind assembly-the Academic Chronicle (academic chroniclers MEETING--ACM), which he named it. and decided to test the participants. The task is to construct the smallest dictionary-ordered stitching (SLC) using n given strings. The SLC of n strings has the smallest dictionary order, and the stitching Si1, ..., i1 in sin, ..., in is an arrangement from 1 to N. It is a glorious thing to be called a chronicle, so don't miss the chance and don't mess it up. Make the Kingdom choose you as the Chronicle.
InputInput
The first line of the input file contains a single integer N (1≤n≤100) indicating the number of strings. The following n lines contain n strings, one string per line. The length of each string was no more than characters. Each of the string consists only of lowercase Latin letters. There is no any leading or trailing spaces.
The first line contains an integer n (1 <= n <= 100) that represents the number of strings. The next n rows contain n strings, one string per line. The length of the string does not exceed 100. Each string contains only the lowercase Latin alphabet, with no header or line trailing spaces.
OutputOutput
Print the SLC of the given N strings to the output file as a.
Outputs a line on the output file that represents the SLC of n given string.
Sample InputSample input
6
It
Looks
Lilke
An
Easy
Problem
Sample OutputSample output
Aneasyitlikelooksproblem
AnalysisAnalysis
At first did not look at the test instructions, only looked at the input output, thought is the dictionary order to connect after the output, later discovered is makes the connection the dictionary order smallest.
Since the concatenated dictionary sequence is minimal, for any two contiguous string x, Y, and only if the dictionary order of X + y is larger than the dictionary order of Y + X, the order is straightforward.
SolutionSolution Solutions
#include <iostream> #include <string> #include <algorithm>using namespace std;const int MAX = 128; String Pdata[max];int cmp (string x, string y) {return x + y < y + x;} int main () {int n;while (cin >> N) {for (int i = 1; I <= N; i++) {cin >> pdata[i];} Sort (pData + 1, pData + n + 1, CMP), for (int i = 1; I <= N; i++) {cout << pdata[i];} cout << Endl;} return 0;}
This topic is generally not difficult, but to gross position the dictionary order to the smallest conversion to the problem of sorting, itself still has a certain degree of difficulty.
And in the future must seriously read the problem, can not directly see the input and output.
But I think this problem seems to be in English.
SGU[347] Join the Strings