fork download
  1. // http://w...content-available-to-author-only...t.com/judge/problem/read/XHAENEUNG
  2. #include <iostream>
  3. #include <list>
  4.  
  5. using namespace std;
  6.  
  7. int convert_s_i(string a)
  8. {
  9. if(a.compare("zero") == 0) return 0;
  10. if(a.compare("one") == 0) return 1;
  11. if(a.compare("two") == 0) return 2;
  12. if(a.compare("three") == 0) return 3;
  13. if(a.compare("four") == 0) return 4;
  14. if(a.compare("five") == 0) return 5;
  15. if(a.compare("six") == 0) return 6;
  16. if(a.compare("seven") == 0) return 7;
  17. if(a.compare("eight") == 0) return 8;
  18. if(a.compare("nine") == 0) return 9;
  19. if(a.compare("ten") == 0) return 10;
  20.  
  21. return -1;
  22. }
  23.  
  24. string convert_i_s(int num)
  25. {
  26. switch(num)
  27. {
  28. case 0: return "zero" ;
  29. case 1: return "one" ;
  30. case 2: return "two" ;
  31. case 3: return "three" ;
  32. case 4: return "four" ;
  33. case 5: return "five" ;
  34. case 6: return "six" ;
  35. case 7: return "seven" ;
  36. case 8: return "eight" ;
  37. case 9: return "nine" ;
  38. case 10: return "ten" ;
  39.  
  40. default :
  41. return 0;
  42. }
  43. }
  44.  
  45. int compute(int a, int b, char operate)
  46. {
  47. if(operate == '+') return a + b;
  48. if(operate == '-') return a - b;
  49. if(operate == '*') return a * b;
  50. if(operate == '/') return a / b;
  51.  
  52. return -1;
  53. }
  54.  
  55. int main()
  56. {
  57. int testcase;
  58. cin >> testcase;
  59.  
  60. for(int counter1 = 0 ; counter1 < testcase ; counter1++)
  61. {
  62. int a, b, real_answer;
  63. string s_a, s_b, s_c, s_compute;
  64. char operate, dummy;
  65.  
  66. cin >> s_a >> operate >> s_b >> dummy >> s_c;
  67. cout << s_a << " " << operate << " " << s_b << " " << dummy << " " << s_c << endl;
  68.  
  69. a = convert_s_i(s_a);
  70. b = convert_s_i(s_b);
  71. real_answer = compute(a, b, operate);
  72. s_compute = convert_i_s(real_answer);
  73.  
  74. int s_compute_size = s_compute.size();
  75. int s_c_size = s_c.size();
  76. list<char> l_compute, l_c;
  77. list<char>::iterator it1 = l_compute.begin();
  78. list<char>::iterator it2 = l_c.begin();
  79.  
  80. // debug
  81. // cout << " size : " << s_compute_size << " " << s_c_size << endl;
  82.  
  83. if(s_compute_size != s_c_size)
  84. cout << "No" << endl;
  85. else
  86. {
  87. for(int counter = 0 ; counter < s_compute_size ; counter++)
  88. {
  89. if(s_compute.at(counter) >= 'a' && s_compute.at(counter) <= 'z')
  90. l_compute.push_front(s_compute.at(counter));
  91. }
  92. for(int counter = 0 ; counter < s_c_size ; counter++)
  93. {
  94. if(s_c.at(counter) >= 'a' && s_c.at(counter) <= 'z')
  95. l_c.push_front(s_c.at(counter));
  96. }
  97.  
  98. l_compute.sort();
  99. l_c.sort();
  100.  
  101. bool f_success = true;
  102.  
  103. // avoid dummy char (like \n, null)
  104. it1++;
  105. it2++;
  106.  
  107. for(int counter = 0 ; counter < s_compute_size ; counter++)
  108. {
  109. // cout << *it1 << " " << *it2 << endl;
  110.  
  111. if(*it1++ != *it2++)
  112. {
  113. f_success = false;
  114. break;
  115. }
  116. }
  117.  
  118. if(f_success)
  119. cout << "Yes" << endl;
  120. else
  121. cout << "No" << endl;
  122. }
  123. }
  124. }
  125.  
Success #stdin #stdout 0s 3424KB
stdin
2
two + three = ivef
zero * zero = one
stdout
two + three = ivef
Yes
zero * zero = one
No