fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <stdio.h>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. int ile;
  9. long long y=0, x1;
  10. string x;
  11.  
  12. void wynik (string);
  13. int liczba (string, int);
  14.  
  15. int main()
  16. {
  17.  
  18. cin >> ile;
  19. cin.get();
  20.  
  21. for (int i=0; i<ile; i++)
  22. {
  23. getline(cin,x);
  24. wynik(x);
  25. }
  26. return 0;
  27. }
  28.  
  29. void wynik (string a)
  30. {
  31. y=0;
  32. for (int j=0; j<x.length(); j++)
  33. {
  34. x1=0;
  35.  
  36. if (j==0)
  37. {
  38. if (x[j]>47 && x[j]<58)
  39. {
  40. string l;
  41. for (int k=j; k<x.length(); k++)
  42. {
  43. l+=x[k];
  44. }
  45. sscanf(l.c_str(), "%d", &x1);
  46.  
  47. y=x1;
  48. }
  49. }
  50. else if (x[j]==43)
  51. {
  52. liczba(x,j);
  53. y+=x1;
  54. }
  55. else if (x[j]==45)
  56. {
  57. liczba(x,j);
  58. y-=x1;
  59. }
  60. else if (x[j]==42)
  61. {
  62. liczba(x,j);
  63. y*=x1;
  64. }
  65. else if (x[j]==61)
  66. {
  67. if (y%2==0)
  68. cout << "TAK" << endl;
  69. else
  70. cout << "NIE" << endl;
  71. }
  72.  
  73. }
  74.  
  75.  
  76. }
  77. int liczba (string a, int j)
  78. {
  79. string l;
  80. for (int k=j+2; k<x.length(); k++)
  81. {
  82. if (x[k]>47 && x[k]<58)
  83. l+=x[k];
  84. else
  85. break;
  86. }
  87. sscanf(l.c_str(), "%d", &x1);
  88. return x1;
  89. }
Success #stdin #stdout 0s 3476KB
stdin
3
7 + 8 * 3 + 9 - 1 =
4 * 5 - 9 - 1 =
7 * 8 - 10 * 10 =
stdout
NIE
TAK
TAK