stringstream的大用处
AC代码:
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
using namespace std;
const int maxn = 1000;
int a[maxn];
int main()
{
string line;
while (cin >> line)
{
for (int i = 0; i < line.length(); i++)
{
if (line[i] == '5')
line[i] = ' ';
}
int n = 0, x;
stringstream ss(line);
while (ss >> x)
a[n++] = x;
sort(a, a + n);
printf("%d", a[0]);
for (int i = 1; i < n; i++)
printf(" %d", a[i]);
printf("\n");
}
// system("pause");
return 0;
}
使用stringstream处理数据
本文介绍了一个使用C++标准库中的stringstream来处理字符串中数字的方法。通过对输入字符串进行预处理,去除特定字符,并将剩余部分解析为整数数组,然后对其进行排序。此方法适用于需要从文本中提取并操作数字的场景。
594

被折叠的 条评论
为什么被折叠?



