- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Different_String.cpp
More file actions
Latest commit
31 lines (30 loc) · 661 Bytes
/
Copy pathB_Different_String.cpp
File metadata and controls
31 lines (30 loc) · 661 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<bits/stdc++.h>
usingnamespacestd;
intmain()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
string s;
cin >> s;
string r = s;
bool found = false;
sort(r.begin(), r.end());
if (r == s) {
// Try next_permutation to find a different arrangement
if (next_permutation(r.begin(), r.end())) {
cout << "YES\n";
cout << r << "\n";
} else {
cout << "NO\n";
}
} else {
cout << "YES\n";
cout << r << "\n";
}
}
return0;
}