+ 1

Can someone pls 🙏 help.I am working on secret messages. I need hint 🤔. Senior programmers,pls help your little boy 🙇

include <iostream> using namespace std; string Reversed_Alpha(string X){ string Nword; string O_alpha="abcdefghijklmnopqrstuvwxyz",Co_alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ",U_alpha="zyxwvutsrqponmlkjihgfedcba"; for(int i=0;i<X.size();i++){ for(int k=0;k<=25;k++){ if(X[i]==O_alpha[k]||X[i]==Co_alpha[k]){ X[i]=U_alpha[k]; Nword+=X[i]; } } } return Nword ; } int main() { string word; cin>>word ; cout<<Reversed_Alpha(word); return 0; }

21st Jun 2022, 11:34 AM
Ayomo Joshua Odunayo
Ayomo Joshua Odunayo - avatar
7 Réponses
+ 1
Actually the "#include " is there. But how do I use the getline() function? I'm asking this because the getline () function is not added in the c++ lesson. Pls, put me through 🤔.
21st Jun 2022, 12:07 PM
Ayomo Joshua Odunayo
Ayomo Joshua Odunayo - avatar
+ 1
Manav Roy Have tried it but still not giving the correct output
21st Jun 2022, 12:24 PM
Ayomo Joshua Odunayo
Ayomo Joshua Odunayo - avatar
+ 1
Yeah💪,I have solved it. The code goes thus: #include <iostream> using namespace std; string Reversed_Alpha(string X){ string Nword; string O_alpha="abcdefghijklmnopqrstuvwxyz ",Co_alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ ",U_alpha="zyxwvutsrqponmlkjihgfedcba "; for(int i=0;i<X.size();i++){ for(int k=0;k<=26;k++){ if(X[i]==O_alpha[k]||X[i]==Co_alpha[k]){ X[i]=U_alpha[k]; Nword+=X[i]; break; } } } return Nword; } int main() { string word; getline(cin,word); cout<<Reversed_Alpha(word); return 0; }
21st Jun 2022, 12:48 PM
Ayomo Joshua Odunayo
Ayomo Joshua Odunayo - avatar
+ 1
Thanks Manav Roy
21st Jun 2022, 4:51 PM
Ayomo Joshua Odunayo
Ayomo Joshua Odunayo - avatar
+ 1
Manav Roy Which method did you use to solve yours? Is this not the usage of characters?
21st Jun 2022, 4:58 PM
Ayomo Joshua Odunayo
Ayomo Joshua Odunayo - avatar
0
Ooh thanks Learning never end . tolower() function 🤔
21st Jun 2022, 5:09 PM
Ayomo Joshua Odunayo
Ayomo Joshua Odunayo - avatar
0
Manav Roy I made some adjustments to the example you provided - Same functionality, just a bit cleaner. https://code.sololearn.com/c56W1wdhRPSS/?ref=app
22nd Jun 2022, 1:02 AM
DinoBambino