fork(1) 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. for (int j=0; j<x.length(); j++)
  32. {
  33. string l, l1, l2; int y, z, m1=0, m2=0;
  34. if (x[j]==42)
  35. {
  36. for (int k=j+2; k<x.length(); k++)
  37. {
  38. if (x[k]>47 && x[k]<58)
  39. {l1+=x[k]; m1++;}
  40. else
  41. break;
  42. }
  43. sscanf(l1.c_str(), "%d", &y);
  44. x.erase(j+2, m1+1);
  45. string l3;
  46. for (int k=j-2; k<x.length(); k--)
  47. {
  48. if (x[k]>47 && x[k]<58)
  49. {l3+=x[k];m2++;}
  50. else
  51. break;
  52. }
  53. for (int k=l3.length()-1; k>=0; k--)
  54. {
  55. l2+=l3[k];
  56. }
  57. sscanf(l2.c_str(), "%d", &z);
  58. x1=y*z;
  59. sprintf((char*)l.c_str(), "%d", x1); // zamiana int na string
  60. l1 = l.c_str();
  61. x.insert(j+1, l1);
  62. x.erase(j-(1+m2), m2+2);
  63. }
  64. }
  65. y=0;
  66. for (int j=0; j<x.length(); j++)
  67. {
  68. x1=0;
  69. if (j==0)
  70. {
  71. if (x[j]>47 && x[j]<58)
  72. {
  73. string l;
  74. for (int k=j; k<x.length(); k++)
  75. {
  76. l+=x[k];
  77. }
  78. sscanf(l.c_str(), "%d", &x1);
  79. y=x1;
  80. }
  81. }
  82. else if (x[j]==43)
  83. {
  84. liczba(x,j);
  85. y+=x1;
  86. }
  87. else if (x[j]==45)
  88. {
  89. liczba(x,j);
  90. y-=x1;
  91. }
  92. else if (x[j]==61)
  93. {
  94. if (y%2==0)
  95. cout << "TAK" << endl;
  96. else
  97. cout << "NIE" << endl;
  98. }
  99. }
  100. }
  101.  
  102. int liczba (string a, int j)
  103. {
  104. string l;
  105. for (int k=j+2; k<x.length(); k++)
  106. {
  107. if (x[k]>47 && x[k]<58)
  108. l+=x[k];
  109. else
  110. break;
  111. }
  112. sscanf(l.c_str(), "%d", &x1);
  113. return x1;
  114. }
Success #stdin #stdout 0s 3476KB
stdin
4
7 + 8 * 3 + 9 - 1 =
4 * 5 - 9 - 1 =
7 * 8 - 10 * 10 =
1 + 0 * 4 =
stdout
NIE
TAK
TAK
NIE