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

wa啊,老是wa,用的字符串,跟用fun的对过了。不知道怎么还是wa,贴代码求助

Posted by BloodElf at 2009-01-19 02:12:44 on Problem 1504
#include<stdio.h>
#include<string.h>

int main()
{
	int n,lb,i,j,k,sa,sb;
	char a[20],b[20];
	scanf("%d",&n);
	while(n--){
		scanf("%s%s",a,b);
		sa=sb=0;
		while(a[sa]=='0')
			sa++;
		while(b[sb]=='0')
			sb++;
		for(i=strlen(a);i<20;i++)
			a[i]='0';
		lb=strlen(b);
		for(i=sb,j=sa;i<lb;i++,j++){
			a[j]+=b[i]-'0';
			if(a[j]>'9'){
				a[j]-=10;
				a[j+1]++;
			}
		}
		i=0;
		while(a[i]=='0')
			i++;
		j=19;
		while(a[j]=='0')
			j--;
		for(k=i;k<=j;k++)
			printf("%c",a[k]);
		printf("\n");
	}
	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