Advertisement
lalalalalalalaalalla

Untitled

Jun 30th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <iomanip>
  5. #include <queue>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <tuple>
  9. #include <iomanip>
  10. #include <stdio.h>
  11. #include <numeric>
  12. #include <map>
  13. #include <math.h>
  14. #include <bitset>
  15.  
  16. #define int long long
  17. #define ull unsigned long long
  18. #define all(a) a.begin(), a.end()
  19. #define pii pair<int, int>
  20. #define pb push_back
  21.  
  22. using namespace std;
  23.  
  24. const double PI = 3.14159265358;
  25.  
  26. long long gcd(long long a, long long b) {
  27. if (a==0) return b;
  28. if (b==0) return a;
  29. if (a>b) return gcd(a%b,b); else return gcd(b%a,a);
  30. }
  31. int prime(int p) { // 1 - простое
  32. for (int i=2;i*i<=p;i++) {
  33. if (p%i==0 && i<p) return 0;
  34. }
  35. return 1;
  36. }
  37.  
  38. double s(int x1, int y1, int x2, int y2) {
  39. return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  40. }
  41.  
  42. int fibonacci(int q) {
  43. if (q == 0) return 0;
  44. if (q < 3) return 1;
  45. return fibonacci(q - 1) + fibonacci(q - 2);
  46. }
  47.  
  48. bool q(int x, int y) {
  49. return ((x % 2 == 0 or y % 2 == 0) and not (x % 2 == 0 and y % 2 == 0));
  50. }
  51.  
  52. signed main()
  53. {
  54. ios_base::sync_with_stdio(0);
  55. cin.tie(0);
  56. cout.tie(0);
  57. string s;
  58. cin >> s;
  59. int op = -1, eq = -1;
  60. bool correct = true;
  61. if (find(all(s), '+') != s.end()) op = find(all(s), '+') - s.begin();
  62. if (find(all(s), '-') != s.end()) op = find(all(s), '-') - s.begin();
  63. if (find(all(s), '*') != s.end()) op = find(all(s), '*') - s.begin();
  64. if (find(all(s), '/') != s.end()) op = find(all(s), '/') - s.begin();
  65. if (find(all(s), '=') != s.end()) eq = find(all(s), '=') - s.begin();
  66. else correct = false;
  67. int n = s.size();
  68. if (op == 0 or op > eq or op + 1 == eq or eq == n - 1 or op == -1 or eq == -1) correct = false;
  69. int first = 0, second = 0, third = 0;
  70. for (int i = 0; i < op; i++) {
  71. if (s[i] >= '0' and s[i] <= '9') first = first * 10 + (s[i] - '0');
  72. else correct = false;
  73. }
  74. for (int i = op + 1; i < eq; i++) {
  75. if (s[i] >= '0' and s[i] <= '9') second = second * 10 + (s[i] - '0');
  76. else correct = false;
  77. }
  78. for (int i = eq + 1; i < n; i++) {
  79. if (s[i] >= '0' and s[i] <= '9') third = third * 10 + (s[i] - '0');
  80. else correct = false;
  81. }
  82. if (correct) {
  83. if (s[op] == '+') {
  84. if (first + second == third) cout << "YES";
  85. else cout << "NO";
  86. } else if (s[op] == '-') {
  87. if (first - second == third) cout << "YES";
  88. else cout << "NO";
  89. } else if (s[op] == '*') {
  90. if (first * second == third) cout << "YES";
  91. else cout << "NO";
  92. } else if (s[op] == '/') {
  93. if ((double)first / second == (double)third) cout << "YES";
  94. else cout << "NO";
  95. } else cout << "ERROR";
  96. } else cout << "ERROR";
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement