0
点赞
收藏
分享

微信扫一扫

AtCoder Beginner Contest 083 (AB)

善解人意的娇娇 2022-05-25 阅读 75

A - Libra

题目链接:​​https://abc083.contest.atcoder.jp/tasks/abc083_a​​

Time limit : 2sec / Memory limit : 256MB

Score : 100 points

Problem Statement

A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.

Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.

Print ​​Left​​​ if the balance scale tips to the left; print ​​Balanced​​​ if it balances; print ​​Right​​ if it tips to the right.

Constraints

  • 1≤A,B,C,D≤10
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print ​​Left​​​ if the balance scale tips to the left; print ​​Balanced​​​ if it balances; print ​​Right​​ if it tips to the right.

Sample Input 1

Copy

3 8 7 1

Sample Output 1

Copy

Left

The total weight of the masses on the left pan is 11, and the total weight of the masses on the right pan is 8. Since 11>8, we should print ​​Left​​.

Sample Input 2

Copy

3 4 5 2

Sample Output 2

Copy

Balanced

The total weight of the masses on the left pan is 7, and the total weight of the masses on the right pan is 7. Since 7=7, we should print ​​Balanced​​.

Sample Input 3

Copy

1 7 6 4

Sample Output 3

Copy

Right

The total weight of the masses on the left pan is 8, and the total weight of the masses on the right pan is 10. Since 8<10, we should print ​​Right​​.

AtCoder Beginner Contest 083 (AB)_i++AtCoder Beginner Contest 083 (AB)_git_02

1 #include <iostream>
2 using namespace std;
3 int N,A,B;
4 int test(int x)
5 {
6 int sum=0;
7 while(x){
8 sum+=x%10;
9 x/=10;
10 }
11 if(sum<=B&&sum>=A) return 1;
12 else return 0;
13 }
14 int main()
15 {
16
17 while(cin>>N>>A>>B){
18 int s=0;
19 for(int i=1;i<=N;i++){
20 if(test(i)) s+=i;
21 }
22 cout<<s<<endl;
23 }
24 return 0;
25 }

View Code

B - Some Sums

题目链接:​​https://abc083.contest.atcoder.jp/tasks/abc083_b​​

Time limit : 2sec / Memory limit : 256MB

Score : 200 points

Problem Statement

Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Constraints

  • 1≤N≤104
  • 1≤AB≤36
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

Sample Input 1

Copy

20 2 5

Sample Output 1

Copy

84

Among the integers not greater than 20, the ones whose sums of digits are between 2 and 5, are: 2,3,4,5,11,12,13,14 and 20. We should print the sum of these, 84.

Sample Input 2

Copy

10 1 2

Sample Output 2

Copy

13

Sample Input 3

Copy

100 4 16

Sample Output 3

Copy

4554


1 #include <iostream>
2 using namespace std;
3 int N,A,B;
4 int test(int x)
5 {
6 int sum=0;
7 while(x){
8 sum+=x%10;
9 x/=10;
10 }
11 if(sum<=B&&sum>=A) return 1;
12 else return 0;
13 }
14 int main()
15 {
16
17 while(cin>>N>>A>>B){
18 int s=0;
19 for(int i=1;i<=N;i++){
20 if(test(i)) s+=i;
21 }
22 cout<<s<<endl;
23 }
24 return 0;
25 }





举报

相关推荐

0 条评论