您的位置:首页 > Web前端

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
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  水题