每天一水SGU347

今天本来应该要写校题解报告的,但是CF跪了,一题都没JUDGE出来,最后比赛取消了~郁闷啊!

后来闲的无事,就到处看看contest,随便点进去一个,看到一水题,几分钟写完,马上就WA了!~

题目的信息含量太低了!我直接看样例。以为是字典序排序后连起来输出,没想到是使得最后连起来的字典序最小。

本来我因为mutilset轻松水过,后来……还是用mutilset水的。重载下小于就好了。

题目:

Description



His Royal Highness King of Berland Berl XV was a very wise man and had a very accomplished wife, who was aware of the fact, that prominent and outstanding personalities once having written down their names on the pages of glorious History, remain there forever. His Royal Highness King Berl XV experienced an intrinsic, lost nowadays, deep and sincere sense of respect and trust for his 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 his royal mind to find the chronicler, who will make him famous, depicting all his heroic deeds truthfully and gloriously enough.

The King assembled the greatest minds of his kingdom at the Academic Chroniclers Meeting (ACM), as he named it, and decided to test their might. The task was to build the Smallest Lexicographical Concatenation (SLC) out of the given N strings. SLC of N strings s 1,..., s N is the lexicographically smallest their concatenation s i1 +... + s iN, where i 1,..., i N is a permutation of integers from 1 through N. It's a great privilege to be a chronicler, so don't miss your chance and don't screw it up! Make the king choose you!

Input

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 is no more than 100 characters. Each string consists only of lowercase Latin letters. There are no any leading or trailing spaces.

Output

Print the SLC of the given N strings to the output file as a single line.

Sample Input

sample input
sample output
6
it
looks
like
an
easy
problem
aneasyitlikelooksproblem

付代码

#include<iostream>
#include<set>
#include<string>
using namespace std;
class mstring{
public:
   string str;
    bool operator<(const mstring &t1) const{
         return (str+t1.str < t1.str+str);
     }
     mstring(){};
     mstring(string a){str=a;};

};
int main(){
  multiset<mstring> s;
  int n;
  while(cin>>n){
  s.clear();
  string str;
  cin.ignore();
  while(n--){
    cin>>str;
    s.insert( mstring(str));
  }
  multiset<mstring> ::iterator itr =s.begin();
  while(itr!=s.end()){

    cout<<(*itr).str;

    itr++;
  }
  cout<<endl;


  }

  return 0;
}

注意到测试数据

2

ac

aca

排出来的应该是acaac 而不是acaca!

比较的方法就是 a+b<b+a!

你可能感兴趣的:(每天一水SGU347)