HDU-1106 题解
排序
题目大意
把字符串中的5看成空格,对得到的数字进行排序
Time: 1000 ms
Memory: 32768 kB
解题思路及分析
字符串流 + STL-sort
AC代码
#include <bits/stdc++.h>
using namespace std;
int a[400];
int sz = 0;
int main()
{
string s;
while (cin >> s)
{
for (int i = 0; i < s.size(); i++)
{
if (s[i] == '5')
{
s[i] = ' ';
}
}
stringstream sin(s);
sz = 0;
int x, f = 1;
while (sin >> x)
{
a[sz++] = x;
}
sort(a, a + sz);
for (int i = 0; i < sz; i++)
{
if (f) f = 0;
else printf(" ");
printf("%d", a[i]);
}
puts("");
}
return 0;
}