【题意】:直接求解就行。注意这个测试用例 15555555555552。
WA一次(缺少temp为0的判断):
if (!strlen(temp))
continue;#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAX 1000+10
int toInt(char str[])
{
return atoi(str);
}
int main()
{
char str[MAX];
while (cin >> str)
{
int i = 0, cnt = 0;
int num[MAX];
char temp[MAX];
for (i = 0; i < strlen(str); i++)
{
int j = 0;
while (true)
{
if ('5' == str[i] || '\0' == str[i])
break;
temp[j++] = str[i++];
}
temp[j] = '\0';
if (!strlen(temp))
continue;
num[cnt++] = toInt(temp);
}
sort(num, num+cnt);
for (i = 0; i < cnt; i++)
{
cout << num[i];
if (i != cnt-1)
cout << " ";
}
cout << endl;
}
return 0;
}
原文地址:http://blog.csdn.net/weijj6608/article/details/43370771