fork download
  1.  
  2.  
  3. #include <iostream>
  4. #include <sstream>
  5. #include <string>
  6. #include <vector>
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <sstream>
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14. int Z;cin>>Z;
  15.  
  16. cin.ignore();
  17. while(Z--)
  18. {
  19. // cin.ignore();
  20.  
  21. string s;
  22. getline(cin, s);
  23. if(s.empty()){
  24.  
  25. getline(cin,s);
  26. }
  27. {
  28. istringstream iss(s);
  29. vector<string> numbers;
  30.  
  31. do
  32. {
  33. string sub;
  34. iss >> sub;
  35. numbers.push_back(sub);
  36. } while (iss);
  37.  
  38. string a = numbers[0];
  39. string b = numbers[2];
  40. string result = numbers[4];
  41. int expression=0; int i=0;
  42.  
  43. while(a[i]!='\0')
  44. {
  45. if(a[i]=='m')
  46. { expression=1; break;}
  47. i++;
  48. }
  49.  
  50. i=0;
  51. if(expression!=1)
  52. while(b[i]!='\0')
  53. {
  54. if(b[i]=='m')
  55. {expression=2; break;}
  56. i++;
  57. }
  58.  
  59. i=0;
  60. if(expression!=1 && expression!=2)
  61. while(result[i]!='\0')
  62. {
  63. if(result[i]=='m')
  64. {expression=3; break;}
  65. i++;
  66. }
  67.  
  68. int temp1, temp2;
  69. switch( expression )
  70. {
  71. case 1:
  72. temp1 = atoi(result.c_str());
  73. temp2 = atoi(b.c_str());
  74. cout<<temp1-temp2<<" + "<<b<<" = "<<result<<endl; // cout<<"\n";
  75. break;
  76.  
  77. case 2:
  78. temp1 = atoi(result.c_str());// cout<<temp1<<endl<<temp2<<endl;
  79. cout<<a<<" + "<<temp1-temp2<<" = "<<result<<endl; //cout<<"\n";
  80. break;
  81.  
  82. case 3:
  83. temp1 = atoi(a.c_str());
  84. temp2 = atoi(b.c_str());
  85. cout<<a<<" + "<<b<<" = "<<temp1+temp2<<endl; // cout<<"\n";
  86. break;
  87.  
  88.  
  89.  
  90. }
  91.  
  92. }
  93.  
  94.  
  95.  
  96. }
  97.  
  98. return 0;
  99. }
  100.  
Success #stdin #stdout 0s 3440KB
stdin
3

23 + 47 = machula

3247 + 5machula2 = 3749

machula13 + 75425 = 77038
stdout
23 + 47 = 70
3247 + 3702 = 3749
1613 + 75425 = 77038