现在的位置: 首页 > 综合 > 正文

PAT 1038. Recover the Smallest Number

2018年04月25日 ⁄ 综合 ⁄ 共 730字 ⁄ 字号 评论关闭

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1038

题解:

代码:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
struct ch
{
    char s[15];
}str[10005];
bool cmp(const struct ch &a,const struct ch &b)
{
    char tmpa[30],tmpb[30];
    strcpy(tmpa,a.s);
    strcpy(tmpb,b.s);
    strcat(tmpa,b.s);
    strcat(tmpb,a.s);
    return strcmp(tmpa,tmpb)<0;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; ++i)
        scanf("%s",str[i].s);
    sort(str,str+n,cmp);
    bool flag=false;
    for(int i=0; i<n; ++i)
    {
        for(int j=0; str[i].s[j]!='\0'; ++j)
        {
            if(!(flag==false&&str[i].s[j]=='0'))
            {
                flag=true;
                printf("%c",str[i].s[j]);
            }
        }
    }
    if(flag==false) printf("0");
    printf("\n");
    return 0;
}

来源:http://blog.csdn.net/acm_ted/article/details/20172431

抱歉!评论已关闭.