b.cpp (745B)
1 #include <iostream> 2 #include <vector> 3 #include <unordered_set> 4 #include <unordered_map> 5 #include <algorithm> 6 #include <queue> 7 8 #define ll long long 9 10 using namespace std; 11 12 int main() { 13 int testCases; 14 cin >> testCases; 15 16 // charset = {p,q,w} 17 // find inversion 18 // go from start to end, replacing p's with q's and vice-versa (no change on w's) 19 20 for(int z = 0; z < testCases; ++z) { 21 string current = ""; 22 cin >> current; 23 reverse(current.begin(), current.end()); 24 for(int i = 0; i < current.size(); ++i) { 25 if(current[i] == 'q') 26 current[i] = 'p'; 27 else if(current[i] == 'p') 28 current[i] = 'q'; 29 } 30 cout << current << endl; 31 } 32 }