zoukankan      html  css  js  c++  java
  • 每天一水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 s1,..., sN is the lexicographically smallest their concatenation si1 +... + siN, where i1,..., iN 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!

  • 相关阅读:
    对一个或多个实体的验证失败。有关详细信息,请参阅“EntityValidationErrors”属性。
    Java基础学习笔记四 Java基础语法
    Java基础学习笔记一 Java介绍
    Java基础学习笔记二 Java基础语法
    Elasticsearch重要配置
    Elasticsearch配置
    Elasticsearch安装详解
    Elasticsearch文档查询
    Elasticsearch索引和文档操作
    Angular4项目,默认的package.json创建及配置
  • 原文地址:https://www.cnblogs.com/dengyaolong/p/3697202.html
Copyright © 2011-2022 走看看