你的任務是:對這些分割得到的整數,依從小到大的順序排序輸出。
輸入數據保證:分割得到的非負整數不會大於100000000;輸入數據不可能全由‘5’組成。
Output 對於每個測試用例,輸出分割得到的整數排序的結果,相鄰的兩個整數之間用一個空格分開,每組輸出佔一行。
Sample Input
0051231232050775Sample Output
0 77 12312320
#include<iostream>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<algorithm>
using namespace std;
int r[1001],cnt;
string s;
int a(string s)//字符串變數字
{
stringstream ss(s);
int x;
ss>>x;
return x;
}
int main()
{
while(cin>>s)
{
cnt=0;//記錄最後結果的整數的數量
memset(r,0,sizeof(r));
s+='5';
string t;
while(s.length())
{
t=s.substr(0,s.find('5'));
if(t.length())
{
r[cnt++]=a(t);
s.erase(0,t.length());
}
while(s[0]=='5'&&s.length())
s.erase(0,1);
}
sort(r,r+cnt);
for(int i=0;i<cnt;i++)
printf("%d%c",r[i],i==cnt-1?'\n':' ');
}
return 0;
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
char str[1005];
while(~scanf("%s",str))
{
int cnt=0,a[1005];
char *p=strtok(str,"5");//strtok爲分裂字符串函數 ,第二個元素按照語法要寫雙引號代表字符串
while(p!=NULL)
a[cnt++]=atoi(p),p=strtok(NULL,"5");//分裂以後的首地址就是NULL了
sort(a,a+cnt);
for(int i=0;i<cnt;i++)
printf("%d%c",a[i],i==cnt-1?'\n':' ');
}
return 0;
}