-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Different_String.cpp
More file actions
98 lines (89 loc) · 1.93 KB
/
B_Different_String.cpp
File metadata and controls
98 lines (89 loc) · 1.93 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*____________________________________________________
|Author: Ki6ui-Par1na
|Date: 2024/05/10
|Time: 20:45:06
|Problem: B_Different_String
|_____________________________________________________ */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define print(n) cout << (n) << endl;
#define tc ll t; cin >> t; while(t--)
// Check Prime Number
bool is_prime(int n) {
if (n <= 1)
return false;
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return true;
}
// Factorial Function
ll factorial(int n) {
ll fact = 1;
for (int i = 1; i <= n; i++) {
fact *= i;
}
return fact;
}
// Composite Number Check
bool is_composite(int n) {
return !is_prime(n);
}
// Binary Search
bool bin_search(int l, int r, int arr[], int x) {
while (l <= r) {
int mid = (l + r) / 2;
if (arr[mid] == x) {
return true;
} else if (arr[mid] < x) {
l = mid + 1;
} else {
r = mid - 1;
}
}
return false;
}
// Sum of Digits
ll digit_sum(ll n) {
ll sum = 0;
while (n > 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
void solve() {
tc{
string s; cin >> s;
string ss = s;
sort(s.begin(), s.end());
bool flag = false;
for(int i = 0; i < s.size() -1; i++){
if(s[i] != s[i + 1]){
flag = true;
if(ss == s){
char temp = s[i];
s[i] = s[i + 1];
s[i + 1] = temp;
}
break;
}
}
if(flag){
cout << "YES\n";
cout << s << endl;
}
else cout << "NO\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
return 0;
}