Hello. So I need to execute a word thats given, but letters have to change their places, 1st letter with 2nd, 3rd one with 4th one... I think I need one more variable?
# include <fstream>
# include <iostream>
# include <iomanip>
usingnamespace std;
int main()
{ int a;
string s;
cin >> s;
int n = s.length();
n=a;
for (int i = 0; i < n; i++){
cout << s[n-(a-1)];
cout << s[n-a];
a--;
}
return 0;
}
things to note:
1. string might have whitespace, so use getline(), not cin()
2. think of a sufficiently rare character to substitute for whitespace such that this character is not expected to appear in a string
3. decide how to handle odd/even string size - I have made an assumption as the code shows but you can substitute your own