Advertisement
saira12tabassum19

Untitled

Oct 19th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string binary(int x)
  4. {
  5. int k; string bin="";
  6. while(x!=0)
  7. {
  8. k=x%2;
  9. bin+=k+'0';
  10. x=x/2;
  11. } //cout<<bin<<endl;
  12. return bin;
  13.  
  14. }
  15. int main()
  16. {
  17. map<string,string>ma;
  18. ma["one"]="1";
  19. ma["two"]="2";
  20. ma["three"]="3";
  21. ma["four"]="4";
  22. ma["five"]="5";
  23. ma["six"]="6";
  24. ma["seven"]="7";
  25. ma["eight"]="8";
  26. ma["nine"]="9";
  27. ma["ten"]="10";
  28. ma["eleven"]="11";
  29. ma["twelve"]="12";
  30. ma["thirteen"]="13";
  31. ma["fourteen"]="14";
  32. ma["fifteen"]="15";
  33. ma["sixteen"]="16";
  34. ma["seventeen"]="17";
  35. ma["eighteen"]="18";
  36. ma["nineteen"]="19";
  37. ma["twenty"]="2";
  38. ma["thirty"]="3";
  39. ma["forty"]="4";
  40. ma["fifty"]="5";
  41. ma["sixty"]="6";
  42. ma["seventy"]="7";
  43. ma["eighty"]="8";
  44. ma["ninety"]="9";
  45.  
  46. int t,h=0,th=0,ty=0;
  47. string s,s1="";
  48. cin>>t; cin.ignore();
  49. for(int i=0;i<t;i++)
  50. {
  51. getline(cin,s);
  52. stringstream ss(s);
  53. string word;
  54. while(ss>>word)
  55. {
  56. s1+=ma[word];
  57. if(word=="thousand")th=1;
  58. else if(word=="hundred")h=1;
  59. if(word=="twenty"||word=="thirty"||word=="forty"||word=="fifty"||word=="sixty"||word=="seventy"||word=="eighty"||word=="ninety")ty=1;
  60.  
  61. }
  62. int l=s1.size();
  63. if(h==1&&th==0)
  64. {
  65. if(l==2&&ty==0)s1.insert(s1.begin()+1,'0');
  66. if(l==2&&ty==1)s1.insert(s1.end(),'0');
  67. if(l==1)s1.insert(s1.end(),2,'0');
  68. }
  69. else if(th==1)
  70. {
  71. if(l==3&&h==1&&ty==1)s1.insert(s1.end(),'0');
  72. if(l==2&&h==0&&ty==0)s1.insert(s1.begin()+1,2,'0');
  73. if(l==2&&h==0&&ty==1){s1.insert(s1.begin()+1,'0');s1.insert(s1.end(),'0');}
  74. if(l==2&&h==1&&ty==0)s1.insert(s1.end(),2,'0');
  75. if(l==1)s1.insert(s1.end(),3,'0');
  76.  
  77. }
  78.  
  79. stringstream ss1(s1);
  80. int x; ss1>>x; //cout<<x<<endl;
  81. string a,b;
  82. a=binary(x);
  83. b=a;
  84. reverse(a.begin(),a.end());
  85. if(a==b)cout<<"YES"<<endl;
  86. else cout<<"NO"<<endl;
  87.  
  88.  
  89.  
  90. th=ty=h=0;
  91.  
  92. s1.clear();
  93. }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement