Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

水题共分享

Posted by z1160y at 2009-06-06 17:00:28 on Problem 2572
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator