PAT1038. Recover the Smallest Number

//意识到一个重要错误,一直以为atoi,itoa是windows独有的,linux下不可用,直到刚刚。。。

//string+=比strcat好用多了,字符比较也方便的多,但是用scanf读入string,好麻烦。。。cin读入老是出错不晓得为什么,cin对于空格和换行符的处理还不是很清楚,c++没有系统学习,半c半++中。。。。,刷完一定找机会吧c++系统一下

//突然想起来第一次刷时,居然一个一个字符的比较。。。。。哭晕

#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef struct
{
char str[10];
}node;
vector<node>list;
bool cmp(node a,node b)
{
char s1[20],s2[20];
strcpy(s1,a.str);strcpy(s2,b.str);
strcat(s1,b.str);strcat(s2,a.str);
return strcmp(s1,s2)<0;
}
int main()
{
freopen("input.txt","r",stdin);
int i,n;
long int s;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
node tmp;
scanf("%s",tmp.str);
s=atoi(tmp.str);
if(s!=0)list.push_back(tmp);
}
if(list.size()==0)printf("0");
else
{
sort(list.begin(),list.end(),cmp);
s=atoi(list[0].str);
printf("%ld",s);
for(i=1;i<list.size();i++)printf("%s",list[i].str);
}
printf("\n");
}
return 0;
}

时间: 2024-10-14 00:38:19

PAT1038. Recover the Smallest Number的相关文章

pat1038. Recover the Smallest Number (30)

1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87},

把数组排成最小的数/1038. Recover the Smallest Number

题目描述 输入一个正整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个.例如输入数组{3,32,321},则打印出这三个数字能排成的最小数字为321323. Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87}, we can recov

1038. Recover the Smallest Number (30)

Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87}, we can recover many numbers such like 32-321-3214-0229-87 or 0229-32-87-321-3214 with respect to different

PAT 1038. Recover the Smallest Number (30)

1038. Recover the Smallest Number (30) Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87}, we can recover many numbers such like 32-321-3214-0229-87 or 0229-3

1038. Recover the Smallest Number (30) - 字符串排序

题目如下: Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given {32, 321, 3214, 0229, 87}, we can recover many numbers such like 32-321-3214-0229-87 or 0229-32-87-321-3214 with respect to dif

PAT 1038 Recover the Smallest Number[dp][难]

1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like 32-321-3214-0229-87 or 022

1038 Recover the Smallest Number (30 分)

1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like 32-321-3214-0229-87 or 022

1038 Recover the Smallest Number (30 分)

1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like 32-321-3214-0229-87 or 022

1038 Recover the Smallest Number string还能这样用 cmp真滴强大

Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like 32-321-3214-0229-87 or 0229-32-87-321-3214 with respect to differe