Chatbox

Các bạn vui lòng dùng từ ngữ lịch sự và có văn hóa,sử dụng Tiếng Việt có dấu chuẩn. Chúc các bạn vui vẻ!
27/12/2013 12:12 # 1
vnttqb
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 5/130 (4%)
Kĩ năng: 39/80 (49%)
Ngày gia nhập: 21/03/2011
Bài gởi: 785
Được cảm ơn: 319
[codeforces] A. Lever


A. Lever
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have a description of a lever as string s. We'll represent the string length as record |s|, then the lever looks as a horizontal bar with weights of length |s| - 1 with exactly one pivot. We will assume that the bar is a segment on the Ox axis between points 0 and |s| - 1.

The decoding of the lever description is given below.

 

  • If the i-th character of the string equals "^", that means that at coordinate i there is the pivot under the bar.
  • If the i-th character of the string equals "=", that means that at coordinate i there is nothing lying on the bar.
  • If the i-th character of the string equals digit c (1-9), that means that at coordinate i there is a weight of mass c on the bar.

 

Your task is, given the lever description, print if it will be in balance or not. Assume that the bar doesn't weight anything. Assume that the bar initially is in balance then all weights are simultaneously put on it. After that the bar either tilts to the left, or tilts to the right, or is in balance.

Input

The first line contains the lever description as a non-empty string s (3 ≤ |s| ≤ 106), consisting of digits (1-9) and characters "^" and "=". It is guaranteed that the line contains exactly one character "^". It is guaranteed that the pivot of the lever isn't located in any end of the lever bar.

To solve the problem you may need 64-bit integer numbers. Please, do not forget to use them in your programs.

Output

Print "left" if the given lever tilts to the left, "right" if it tilts to the right and "balance", if it is in balance.

Sample test(s)
input
=^==
output
balance
input
9===^==1
output
left
input
2==^7==
output
right
input
41^52==
output
balance
Note

As you solve the problem, you may find the following link useful to better understand how a lever functions:http://en.wikipedia.org/wiki/Lever.

The pictures to the examples:

 

 

 

 

 

 

 

 



======================================================================================================

Cuộc đời là một dòng sông. Ai không bơi thì chết. 
 

Name: Tien (Tory) TRAN
Email: TranTien29@gmail.com


 
27/12/2013 20:12 # 2
minh_vu_03
Cấp độ: 1 - Kỹ năng: 1

Kinh nghiệm: 7/10 (70%)
Kĩ năng: 3/10 (30%)
Ngày gia nhập: 07/09/2013
Bài gởi: 7
Được cảm ơn: 3
Phản hồi: [codeforces] A. Lever


#include<iostream>
#include<string.h>
#include<stdio.h>
#include<math.h>
using namespace std;
 
bool testDescription(char *s)
{
int i = 0,dem = 0;
while(s[i] == '=' || s[i] == '^' || (s[i] >= '0' && s[i] <= '9'))
{
if(s[i] == '^')
dem++;
i++;
}
if(i < strlen(s) || dem != 1)
return false;
return true;
}
 
void search(int &vt,int node[],char *s)
{
for(int i = 0; i < strlen(s); i++)
{
if(s[i] == '^')
vt = i;
if(s[i] >= '0' && s[i] <= '9')
node[i] = int(s[i] - 48);
}
}
 
void Result(char *s,int vt,int node[])
{
int result = 0;
for(int i = 0; i < strlen(s); i++)
{
if(s[i] >= '0' && s[i] <= '9')
result += node[i]*(vt - i);
}
if(result == 0)
cout<<"balance"<<endl;
else if(result < 0)
cout<<"right"<<endl;
else
cout<<"left"<<endl;
}
 
int main(void)
{
char des[100];
int vt;
int node[100];
do
{
cin.getline(des,100);
fflush(stdin);
}while(testDescription(des) == false);
search(vt,node,des);
Result(des,vt,node);
}



 
30/12/2013 23:12 # 3
BabyCoder
Cấp độ: 1 - Kỹ năng: 1

Kinh nghiệm: 4/10 (40%)
Kĩ năng: 1/10 (10%)
Ngày gia nhập: 12/12/2013
Bài gởi: 4
Được cảm ơn: 1
Phản hồi: [codeforces] A. Lever


Bài đó mình code thế này thôi

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long long vt,i,j,t=0,p=0,d1=0,d2=0;
	vt=s.find("^");
	for (int i=0;i<vt;i++)
		if (s[i]!='=')
			t+=(s[i]-'0')*(vt-i);
	for (int i=vt+1;i<s.size();i++)
		if (s[i]!='=')
			p+=(s[i]-'0')*(i-vt);
	if (t==p) cout<<"balance";
	else if (t<p) cout<<"right";
	else cout<<"left";
}
	



 
Copyright© Đại học Duy Tân 2010 - 2024