不好好审题给自己挖了几个大坑(悲,完全没看见字母升序排列,就说咋改都不对
下标多,写的时候得把脑子拎清楚
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int n;
cin >>n;
vector<string> words(n);
vector<string> chars(n);
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
cin >> words[i];
}
for (int i = 0; i < n; i++)
{
string temp;
for(char c : words[i])
{
if (temp.find(c) == string::npos)
temp += c;
}
sort(temp.begin(), temp.end());
chars[i] = temp;
//cout << "chars"<<i<<":"<<chars[i] << endl;
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < words[i].size(); j++)
{
int t = chars[i].find(words[i][j]);
char ch = chars[i][chars[i].size() - t - 1];
words[i][j] = ch;
}
}
for (string& i:words)
{
cout << i << endl;
}
cin.get();
}
下班!