您的位置:首页 > 其它

HDOJ 1106 排序

2015-02-01 12:14 141 查看
【题意】:直接求解就行。注意这个测试用例 15555555555552。

WA一次(缺少temp为0的判断):

if (!strlen(temp))
continue;


【代码:AC】

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: