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 dawei007 at 2010-04-24 08:31:53 on Problem 3508
#include<stdio.h>
#include<string>
int main()
{
	int index=0;
	while(1)
	{
		char str[1000000];
		scanf("%s",&str);
		++index;
		if( !strcmp(str,"0") )
			break;
		char last = str[strlen(str) - 1];
		int flg = 0;//向高位借位
		for (int j = strlen(str) - 2; j >= 0; j--) 
		{	
			int tt = str[j] - last;
			if (flg + tt < 0) //产生借位:加10,借位
			{
				str[j] = (char) ('0' + flg + tt + 10);
				flg = -1;
			} 
			else 
			{
				str[j] = (char) ('0' + flg + tt);
				flg = 0;
			}
			last = str[j];
		}
		if (str[0] != '0') //首位为0,位数不同,IMPOSSIBLE
			printf("%d. %s\n",index,str);
		else 
			printf("%d. IMPOSSIBLE\n",index);
	}
	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