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 xulinxi at 2010-08-06 11:37:00 on Problem 1503
#include<stdio.h>
#include<string.h>
char a[210][210];
char sum[210];
int cf[210];
int i;
void add(int p,int j)
{
	char k,t,r;
	t=a[p][j]-'0';
	sum[j]+=t+cf[j];
	cf[j]=0;
	r=sum[j]-'0';
	if(r>9)
	{
		cf[j-1]=r/10;
		sum[j]=r%10;
		if(sum[0]>9&&j==0)
		{
			for(k=i;k>=0;k--)
				sum[k+1]=sum[k];
				sum[0]=(sum[1]-'0')/10;
			
				sum[1]=(sum[1]-'0')%10;		
		}
	}
	
	
}
int main()
{
	int j,p,k;
	while(1)
	{
		memset(a,'\0',sizeof(a));
		for(i=0;;++i)
		{
			scanf("%s",a[i]);
			if(a[i][0]=='0'&&a[i][1]=='\0')
			break;
		}
		memset(sum,0,sizeof(sum));
		memset(cf,0,sizeof(cf));
		strcpy(sum,a[0]);
		for(p=1;p<=i;p++)
		{
		
			k=strlen(a[p]);
			for(j=k-1;j>=0;j--)
			{
				add(p,j);
			}
			
		}
		printf("%s\n",sum);
	}
	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