Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <map>
  5. #include <algorithm>
  6. using namespace std;
  7. string s, so;
  8. map<char, char> ma;
  9. int main(){
  10. s="CARScarsIuVEJxTXsUvOHhngyZKfAYmaqolMNtGQibwdjPrCpekFWzLaySBaPybRMgzYMynY";//letters in Martian
  11. so="UnilEPFLvpVZzBNtLSCubWmaocIYneAPqxDshRkMGgJfHrFUQTjXOwdPolyProgisawesome";//corresponding letters in English
  12. /* next for loop creates the Martian-To-English alphabet */
  13. for(int i=0; i<s.length(); i++){
  14. ma.insert(pair<char, char>(s[i], so[i]));
  15. }
  16. int n;
  17. cin>>n;//number of words in string
  18. so="";//this will be the answer
  19. for(int i=0; i<n; i++){
  20. cin>>s;
  21. /* next for loop translates the string 's' from martian to English and writes it in string 'so' */
  22. for(int j=0; j<s.length(); j++){
  23. so+=ma.find(s[j])->second;
  24. if(j==s.length()-1) so+=" ";
  25. }
  26. }
  27. while(so[so.length()-1] == ' ') so=so.substr(0, so.length()-1);//avoiding trailing spaces
  28. string b="";
  29. int i=0;
  30. while(so[i] == ' '){//avoiding leading spaces
  31. i++;
  32. }
  33. for(i; i<so.length(); i++){
  34. b+=so[i];
  35. }
  36. cout<<so;
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement