虽然是一题水题,但还是要考虑到各种情况,不然还是A不了。
有点舒服,一次就A了,还不错。
例子:
0051231232050775
5500501235
123
55565055
0005005
100255001101
结果:
0 77 12312320
0 123
123
0 6
0 0
1002 1101
#include <iostream>
#include <string.h>
#include <string>
#include <cstdio>
#include <algorithm>
using namespace std;
char s[1005];
int a[1000];
int main(int argc, char *argv[])
{
//freopen("D:\\c - free\\hdu_1106\\input.txt","r",stdin);
int i,pos,cnt,flag;
string str;
while (gets(s) && strlen(s) != 0){
str = "";
cnt = 0,flag = 0,pos = 1;
for (i = 0;i < strlen(s);i++){
if (s[i] == '5' && pos == 1) continue;
else if (s[i] == '5'){
if (flag == 0) a[cnt++] = 0;
else a[cnt++] = atoi(str.c_str());
pos = 1;
str = "";
}else if (s[i] == '0' && flag == 0) pos = 0;
else{
str += s[i];
pos = 0,flag = 1;
}
}
if (str != "") a[cnt++] = atoi(str.c_str());
sort(a,a+cnt);
cout<<a[0];
for (i = 1;i < cnt;i++) cout<<' '<<a[i];
cout<<endl;
}
return 0;
}