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

晕,竟是2000位以内的

Posted by lengshu at 2011-09-28 14:08:06 on Problem 1519
#include <stdio.h>
#include <string.h>

int SigDigit(int nInput)
{
	if (nInput < 10)
		return nInput;
	int nSum = 0;
	while(nInput != 0)
	{
		nSum += nInput % 10;
		nInput /= 10;
	}
	return SigDigit(nSum);
}

int main(int argc, char* argv[])
{
	char pInput[2000];
	unsigned int nInput = 0;
	while(scanf("%s", pInput), pInput[0] != '0')
	{
		nInput = 0;
		for (int i = 0; i < strlen(pInput); i++)
		{
			nInput += pInput[i] - '0';
		}
		printf("%d\n", SigDigit(nInput));
	}
	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