例子:
输入:8 23 122 9
输出:9823122
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <sstream>
using namespace std;
int main()
{
int i=0,h;
string str,temp;
vector<string> n;
//读入不确定的长度的正整数
getline(cin,str);
//借用sstream对str进行分割(空格)
stringstream sstr(str);
while(sstr>>temp)
{
n.push_back(temp);
i++;
}
sort(n.begin(),n.end());//字典顺序排序
for(h=i-1;h>=0;h--)
{
cout<<n[h];
}
printf("\n");
return 0;
}
本文介绍了一种处理不定长度正整数的方法,通过字符串流将输入的数字分割成多个部分,并按照字典顺序排序这些部分。最后,程序将排序后的部分逆序输出,实现了数字的重新排列。
1782

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



