| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
水题共分享#include <iostream>
#include <cmath>
using namespace std;
int done(char s[])
{
int len=strlen(s),i,sum=0;
for(i=len-1;i>=0;i--)
{
sum+=(s[i]-'0')*pow(double(10),double(i));
}
return sum;
}
int main()
{
char equ[100];
while(scanf("%s",equ)&&strcmp(equ,"0+0=0"))
{
char a[20]={'\0'},b[20]={'\0'},c[20]={'\0'};
int i,len=strlen(equ),x,y;
for(i=0;i<len;i++)
{
if(equ[i]=='+') x=i;
else if(equ[i]=='=') y=i;
}
strncpy(a,equ,x);
strncpy(b,equ+x+1,y-x-1);
strncpy(c,equ+y+1,len-y-1);
if(done(a)+done(b)==done(c)) cout<<"True"<<endl;
else cout<<"False"<<endl;
}
cout<<"True"<<endl;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator