这道题呀,题意是说给你两个数字(然后你自己算出他们的和),如果把加数以及他们的和里面的零都去掉,这个等式是否还成立
那么就直接把去掉零之后的数字都求出来,计算一下看是不是成立就好啦~
咱们模拟一下就好~ 需要注意一下这个弃掉0的函数怎么写就好^_^
int del0(int x)
{
int ret=0,tmp=x,time=1; //tmp是这个数字,ret是用来存储去掉0的返回值
while(tmp)
{
int digit=tmp%10; //获得当前最低位的数字
if(digit) ret+=(time)*digit,time*=10; //如果不是0就加进去,是0的话无视掉
tmp/=10;
}
return ret;
}
Code:
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int del0(int x)
{
int ret=0,tmp=x,time=1;
while(tmp)
{
int digit=tmp%10;
if(digit) ret+=(time)*digit,time*=10;
tmp/=10;
}
return ret;
}
int main()
{
int a,b;
cin>>a>>b;
int c=a+b;
//cout<< del0(c)<<": "<<del0(a)<<": "<<del0(b)<<endl;
if(del0(c)==del0(a)+del0(b))cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}