PROBLEM LINK:
AUSSIA KRAIN WAR | CodeChef
Author: Charan Narukulla
DIFFICULTY:
CAKEWALK.
PREREQUISITES:
Strings
PROBLEM:
encode a statement S as follows:
1.Any space should be replaced by &
2.If the alphabet is not A/B/C/D/E then they should appear at the end in reverse order. For example, BESTFRIEND will become BEEDNIRFTS.
EXPLANATION:
One can make another string by following given rules. Use string concatenation to form a new string.
SOLUTIONS:
Tester's Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t; cin >> t;
while(t--){
string s; getline(cin>>std::ws,s);
vector<char> v;
for(int i=0; i<s.length(); i++){
if(s[i]=='A' || s[i]=='B' || s[i]=='C' || s[i]=='D' || s[i]=='E'){
cout << s[i];
}
else if(s[i]==' '){
cout << "&";
}
else{
v.push_back(s[i]);
}
}
reverse(v.begin(), v.end());
for(int i=0; i<v.size(); i++){
cout << v[i];
}
cout << endl;
}
return 0;
}