ProgMe

Untitled

Jun 14th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6. string s;
  7. cin >> s;
  8. int left = 0, xleft= 0, right = 0, xright = 0;
  9. bool is_left = 1, now = 1;
  10. for (int i = 0; i < s.size(); i++){
  11. if (s [i] == '=') {
  12. is_left = 0;
  13. now = 1;
  14. continue;
  15. }
  16. if (s [i] == '-'){
  17. now = 0;
  18. continue;
  19. }
  20. if (s [i] == '+'){
  21. now = 1;
  22. continue;
  23. }
  24. if (s [i] == 'x'){
  25. if (now){
  26. if (is_left)
  27. xleft++;
  28. else
  29. xright++;
  30. }
  31. else{
  32. if (is_left)
  33. xleft--;
  34. else
  35. xright--;
  36. }
  37. }
  38. else{
  39. if (now){
  40. if (is_left)
  41. left += (s [i] - '0');
  42. else
  43. right += (s [i] - '0');
  44. }
  45. else{
  46. if (is_left)
  47. left -= (s [i] - '0');
  48. else
  49. right -= (s [i] - '0');
  50. }
  51. }
  52. }
  53. xleft -= xright;
  54. right -= left;
  55. if (xleft == 0){
  56. if (right == 0){
  57. cout << "Infinity\n";
  58. return 0;
  59. }
  60. else{
  61. cout << "No solution\n";
  62. return 0;
  63. }
  64. }
  65. else{
  66. if (right / xleft == (double)right / xleft){
  67. cout << right / xleft << "\n";
  68. return 0;
  69. }
  70. else{
  71. cout << "No solution\n";
  72. return 0;
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment