51nod 1097 拼成最小的数

来源:互联网 发布:教育大数据应用 编辑:程序博客网 时间:2024/06/11 20:45

排序,两个串a,b,,如果ab < ba,则a在前,否则a在后

#include <bits/stdc++.h>using namespace std;const int MAXN = 10010;string strs[MAXN];bool cmp(const string& a, const string& b){    return a+b < b+a;}int main(){    ios::sync_with_stdio(false);    int n;    cin >> n;    for(int i = 0; i < n; ++i)        cin >> strs[i];    sort(strs,strs+n,cmp);    int len = 0;    for(int i = 0; i < n; ++i)    {        for(int j = 0; j < strs[i].length(); ++j)        {            len++;            putchar(strs[i][j]);            if(len%1000 == 0)                putchar('\n');        }    }    return 0;}
原创粉丝点击