Educational Codeforces Round 9 C - The Smallest String Concatenation ,学习到string

题意非常简单,题目很水,:给你n个字符串,按字典序最小的顺序排列。
如果用char 数组将会非常的麻烦,但是你看看用 string 会多么简单

赶紧学习一波string 的用法

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#define mem(a) memset(a,0,sizeof(a))
#define INF 0x7fffffff //INT_MAX
#define inf 0x3f3f3f3f //
const double PI = acos(-1.0);
const double e = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
bool cmpbig(int a,int b){return a>b;}
bool cmpsmall(int a,int b){return a<b;}
using namespace std;

struct str{
    string s;
};
str a[50005];
bool cmp(str a, str b)
{
    string ab = a.s+b.s;
    string ba = b.s+a.s;
    return ab<ba;
}
int main(){
    //freopen("1.txt","r",stdin);
    int n;
    while(~scanf("%d",&n)){
        for(int i=0;i<n;i++){
// printf("i=%d\n",i);
            cin>>a[i].s;
        }
// printf("%d\n",cmp(a[3],a[1]));
        sort(a,a+n,cmp);
        for(int i=0;i<n;i++)
            cout<<a[i].s;
        cout<<endl;
    }
    return 0;
}

你可能感兴趣的:(Educational Codeforces Round 9 C - The Smallest String Concatenation ,学习到string)