题目描述
牛牛举办了一场数字游戏,有n个玩家参加这个游戏,游戏开始每个玩家选定一个数,然后将这个数写在纸上(十进制数,无前缀零),然后接下来对于每一个数字将其数位按照非递减顺序排列,得到新的数,新数的前缀零将被忽略。得到最大数字的玩家赢得这个游戏。
输入描述:
输入包括两行,第一行包括一个整数n(1 ≤ n ≤ 50),即玩家的人数 第二行n个整数x[i](0 ≤ x[i] ≤ 100000),即每个玩家写下的整数。
输出描述:
输出一个整数,表示赢得游戏的那个玩家获得的最大数字是多少。
示例1
输入
3
9638 8210 331
输出
3689
这道题目为了简单,使用string排序,以及转为int再排序的处理方法
#include<iostream>
#include<algorithm>
#include<sstream>
#include<string>
#include<vector>
using namespace std;
const int N = 1000;
string str[N];
int main()
{
int n;
cin >> n;
vector<int> res;
for (int i = 0; i < n; i++) cin >> str[i];
for (int i = 0; i < n; i++) {
int temp;
sort(str[i].begin(), str[i].end());
stringstream stream(str[i]);
stream >> temp;
//cout << temp<<endl;
res.push_back(temp);
}
sort(res.begin(), res.end());
cout << res[n-1] << endl;
}