Codeforces 75A:Life Without Zeros(水题)
2016-05-16 21:06
435 查看
Life Without Zeros
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation a + b = c,
where a and b are
positive integers, and c is the sum of a and b.
Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros?
For example if the equation is 101 + 102 = 203, if we removed all zeros it will be 11 + 12 = 23 which
is still a correct equation.
But if the equation is 105 + 106 = 211, if we removed all zeros it will be 15 + 16 = 211 which
is not a correct equation.
Input
The input will consist of two lines, the first line will contain the integer a, and the second line will contain the integer b which
are in the equation as described above (1 ≤ a, b ≤ 109).
There won't be any leading zeros in both. The value of c should be calculated asc = a + b.
Output
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO"
otherwise.
Examples
input
output
input
output
题意:给你两个数a和b,计算a+b的值,判断将a、b、a+b三个数中的所有0去掉后,结果是否扔成立。
解题思路:对a去零,储存到aa,对b去零,储存到bb,对a+b去零,储存到llast,判断aa+bb是否等于llast。
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation a + b = c,
where a and b are
positive integers, and c is the sum of a and b.
Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros?
For example if the equation is 101 + 102 = 203, if we removed all zeros it will be 11 + 12 = 23 which
is still a correct equation.
But if the equation is 105 + 106 = 211, if we removed all zeros it will be 15 + 16 = 211 which
is not a correct equation.
Input
The input will consist of two lines, the first line will contain the integer a, and the second line will contain the integer b which
are in the equation as described above (1 ≤ a, b ≤ 109).
There won't be any leading zeros in both. The value of c should be calculated asc = a + b.
Output
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO"
otherwise.
Examples
input
101 102
output
YES
input
105 106
output
NO
题意:给你两个数a和b,计算a+b的值,判断将a、b、a+b三个数中的所有0去掉后,结果是否扔成立。
解题思路:对a去零,储存到aa,对b去零,储存到bb,对a+b去零,储存到llast,判断aa+bb是否等于llast。
#include <stdio.h> int main() { int a,b; while(scanf("%d%d",&a,&b)!=EOF) { int last=a+b; int aa=0,bb=0; int llast=0; int ci=1;//控制乘10 while(a)//对a去零,将结果存到aa里面 { if(a%10==0) { a=a/10; continue; } aa=aa+ci*(a%10); ci=ci*10; a=a/10; } ci=1; while(b)//对b去零,将结果存到bb里面 { if(b%10==0) { b=b/10; continue; } bb=bb+ci*(b%10); ci=ci*10; b=b/10; } ci=1; while(last)//对a+b的结果去零,将结果存到llast里面 { if(last%10==0) { last=last/10; continue; } llast=llast+ci*(last%10); ci=ci*10; last=last/10; } if(llast==aa+bb)//看是否符合题意 { printf("YES\n"); } else { printf("NO\n"); } } return 0; }
相关文章推荐
- 【HDU 5366】The mook jong 详解
- HDU 5240 Exam (好水的题)
- 北大—1006——Biorhythms
- 时间计算(heaven.pas/cpp)
- 工作依赖(job.cpp/pas)
- 题目 英雄 (BFS)
- kmp 学习 hihocoder #1015
- HDU 1096 A+B for Input-Output Practice (VIII)
- HUST-1601 - Shepherd 暴力
- P1478
- P1035
- P1008 难度2.7
- 2020 绝对值排序
- 2021 发工资咯
- 2022 海选女主角
- 2024 C语言合法标识符
- 2025 查找最大元素
- 2026 首字母变大写
- 2027 统计元音
- 2028 Lowest Common Multiple Plus