poj 1503 Integer Inquiry

大数相加

#include <stdio.h>
#include <string.h>
const int MAXN=400;
int main(int argc, char *argv[])
{
	int i,j,n;
	int sum[MAXN],flag=0;
	char ch[MAXN];
	memset(sum,0,sizeof(sum));
	
	while(1)
	{
		memset(ch,0,sizeof(ch));
		scanf("%s",ch);
		if (!strcmp(ch,"0"))//排除0023 这种输入 
		{
			for (i=MAXN-1;i>=0;i--)
			  if(sum[i]) break;
			for (;i>=0;i--)
			  printf("%d",sum[i]);
	        if(flag==0) printf("0");//第一个数就打的0,就打印0 
			printf("\n");
			
			break; 
			 
		}
		else flag=1;
		int len=strlen(ch);
		for (i=0;i<len/2;i++)
		{
			char t=ch[i];
			ch[i]=ch[len-1-i];
			ch[len-1-i]=t;
		}
		for (i=0;i<len;i++)
		  ch[i]-=48;
		int c=0;  
		for (i=0;i<MAXN;i++)
		{
			int s=ch[i]+sum[i]+c;
			sum[i]=s%10;
			c=s/10;
		}
	} 
	return 0;
}


 

你可能感兴趣的:(poj 1503 Integer Inquiry)