fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define space " "
  4. #define tab "\t"
  5. #define case(t) cout<<"Case "<<t<<": ";
  6. #define pi acos(-1.0)
  7. int val( map<string,int>mymap,int value,string str)
  8. {
  9.  
  10. if(str.length()>2)
  11. {
  12. if(str=="hundred" || str=="thousand")
  13. {
  14. value*=mymap[str];
  15. }
  16. else
  17. value+=mymap[str];
  18. }
  19.  
  20. return value;
  21. }
  22.  
  23. bool binary(int value)
  24. {
  25. string str1,str2;
  26. while(value)
  27. {
  28. str1+=(value%2)+48;
  29. value/=2;
  30.  
  31. }
  32. str2=str1;
  33. reverse(str1.begin(),str1.end());
  34. //cout<<str1<<endl;
  35. if(str1==str2)
  36. return 1;
  37.  
  38. return 0;
  39.  
  40. }
  41. int main()
  42. {
  43.  
  44. map<string,int>mymap;
  45. mymap["zero"]=0;
  46. mymap["one"]=1;
  47. mymap["two"]=2;
  48. mymap["three"]=3;
  49. mymap["four"]=4;
  50. mymap["five"]=5;
  51. mymap["six"]=6;
  52. mymap["seven"]=7;
  53. mymap["eight"]=8;
  54. mymap["nine"]=9;
  55. mymap["ten"]=10;
  56. mymap["eleven"]=11;
  57. mymap["twelve"]=12;
  58. mymap["thirteen"]=13;
  59. mymap["fourteen"]=14;
  60. mymap["fifteen"]=15;
  61. mymap["sixteen"]=16;
  62. mymap["seventeen"]=17;
  63. mymap["eighteen"]=18;
  64. mymap["nineteen"]=19;
  65.  
  66. mymap["twenty"]=20;
  67.  
  68. mymap["thirty"]=30;
  69.  
  70. mymap["forty"]=40;
  71.  
  72. mymap["fifty"]=50;
  73.  
  74. mymap["sixty"]=60;
  75.  
  76. mymap["seventy"]=70;
  77.  
  78. mymap["eighty"]=80;
  79.  
  80. mymap["ninety"]=90;
  81. mymap["hundred"]=100;
  82. mymap["thousand"]=1000;
  83.  
  84.  
  85. int t;
  86. cin>>t;
  87. //t++;
  88. while(t--)
  89. {
  90. int value=0;
  91.  
  92. string str;
  93. char ch;
  94. while(1)
  95. {
  96. ch=getchar();
  97.  
  98. if(ch=='\n')
  99. {
  100. value=val(mymap,value,str);
  101. break;
  102. }
  103.  
  104. if(ch>='a' && ch<='z')
  105. {
  106. str+=ch;
  107. }
  108. else
  109. {
  110.  
  111. value=val(mymap,value,str);
  112. str.clear();
  113. }
  114. }
  115.  
  116. if(value>0)
  117. {
  118.  
  119. if(binary(value))
  120. cout<<"YES"<<endl;
  121. else
  122. cout<<"NO"<<endl;
  123. }
  124.  
  125. }
  126.  
  127. return 0;
  128. }
  129.  
Success #stdin #stdout 0s 4320KB
stdin
3
two
two hundred fifty five
five
stdout
NO
YES