Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- string s;
- cin >> s;
- int left = 0, xleft= 0, right = 0, xright = 0;
- bool is_left = 1, now = 1;
- for (int i = 0; i < s.size(); i++){
- if (s [i] == '=') {
- is_left = 0;
- now = 1;
- continue;
- }
- if (s [i] == '-'){
- now = 0;
- continue;
- }
- if (s [i] == '+'){
- now = 1;
- continue;
- }
- if (s [i] == 'x'){
- if (now){
- if (is_left)
- xleft++;
- else
- xright++;
- }
- else{
- if (is_left)
- xleft--;
- else
- xright--;
- }
- }
- else{
- if (now){
- if (is_left)
- left += (s [i] - '0');
- else
- right += (s [i] - '0');
- }
- else{
- if (is_left)
- left -= (s [i] - '0');
- else
- right -= (s [i] - '0');
- }
- }
- }
- xleft -= xright;
- right -= left;
- if (xleft == 0){
- if (right == 0){
- cout << "Infinity\n";
- return 0;
- }
- else{
- cout << "No solution\n";
- return 0;
- }
- }
- else{
- if (right / xleft == (double)right / xleft){
- cout << right / xleft << "\n";
- return 0;
- }
- else{
- cout << "No solution\n";
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment