-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathA_Lever.cpp
47 lines (40 loc) · 1.15 KB
/
A_Lever.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Problem Link : https://codeforces.com/problemset/problem/376/A
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
cin >> str;
long long int left = 0;
int n = str.length();
int i = 0;
while(i < n && str[i] != '^')i++; // searching for pivot
// it there is a weight on the left side then i will add that into left and if there is a weight on the right then i will substract that from right
// with help of last value of left i will deside that this is balance or not.
int dist = 1;
while(i-dist >= 0 && i+dist < n){
if(str[i-dist] != '=')
left += (str[i-dist]-'0')*dist;
if(str[i+dist] != '=')
left -= (str[i+dist]-'0')*dist;
dist++;
}
while(i-dist >= 0){
if(str[i-dist] != '=')
left += (str[i-dist]-'0')*dist;
dist++;
}
while(i+dist < n){
if(str[i+dist] != '=')
left -= (str[i+dist]-'0')*dist;
dist++;
}
if(left == 0){
cout << "balance" << endl;
}else if(left < 0){
cout << "right" << endl;
}else{
cout << "left" << endl;
}
return 0;
}