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

我的c: 过得好辛苦^

Posted by gardner at 2005-10-14 09:29:08 on Problem 2602
#include <stdio.h>
void main()
{
	int a,b,counter;
	long length,sum,i,len;
	long result[120000];
	sum=0;
	counter=0;
	scanf("%ld",&length);
	for(i=0;i<length;i++){
		scanf("%d%d",&a,&b);
		sum=sum*10+a+b;
		counter++;
		if(counter==9){
			result[i/9]=sum;
			sum=0;
			counter=0;
		}
	}
	if(counter!=0)result[i/9]=sum;
	len=(length-1)/9;
	if(len>=1){
		switch(counter){
		case 1:if(result[len]>=10){
			result[len-1]++;
			result[len]%=10;
			   }
			break;
		case 2:if(result[len]>=100){
			result[len-1]++;
			result[len]%=100;
			   }
			break;
		case 3:if(result[len]>=1000){
			result[len-1]++;
			result[len]%=1000;
			   }
			break;
		case 4:if(result[len]>=10000){
			result[len-1]++;
			result[len]%=10000;
			   }
			break;
		case 5:if(result[len]>=100000){
			result[len-1]++;
			result[len]%=100000;
			   }
			break;
		case 6:if(result[len]>=1000000){
			result[len-1]++;
			result[len]%=1000000;
			   }
			break;
		case 7:if(result[len]>=10000000){
			result[len-1]++;
			result[len]%=10000000;
			   }
			break;
		case 8:if(result[len]>=100000000){
			result[len-1]++;
			result[len]%=100000000;
			   }
			break;
		default:break;
		}
	}
	for(i=(length-1)/9;i>=1;i--){
		if(result[i]>=1000000000){
			result[i-1]++;
			result[i]%=1000000000;
		}
	}
	for(i=0;i<(length-1)/9;i++)printf("%09ld",result[i]);
	switch(counter){
	case 0:printf("%09ld",result[len]);break;
	case 1:printf("%01ld",result[len]);break;
	case 2:printf("%02ld",result[len]);break;
	case 3:printf("%03ld",result[len]);break;
	case 4:printf("%04ld",result[len]);break;
	case 5:printf("%05ld",result[len]);break;
	case 6:printf("%06ld",result[len]);break;
	case 7:printf("%07ld",result[len]);break;
	case 8:printf("%08ld",result[len]);break;
	}
	printf("\n");
}

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