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 wangjiayu at 2010-07-25 09:52:24 on Problem 2190
#include<stdio.h>
#include<math.h>
int main()
{
	int i,k,sum = 0,j = 0;
	char a[11] = {0};
	scanf("%s",a);
	for(i = 0;i<10;i++)
	{
		if(a[i] == 'X')
		{
			a[i] = 10 + '0';
		}
		if(a[i] == '?')
		{
			k = i;
		}
		else          // if(a[i] != '?')
		{
			sum = sum + (a[i] - '0') * (10 - i);		
		}
	}
	if(k == 9)
	{
		for(i = 0;i<=10;i++)
		{
			if((sum + i*(10 - k))%11 == 0)
			{
				if(i == 10 && k == 9)
				{
					printf("X\n");break;			
				}
				else if(i == 10 && k!= 9)
				{
					printf("-1\n");break;
				}
				else if(i!= 10)
				{
					printf("%d\n",i);break;				
				}
			}
			//sum = sum - i*(10 - k);
		}
		if(i == 11)
		{
			printf("-1\n");
		}	
	}
	else
	{
		for(i = 0;i<=9;i++)
		{
			sum = sum + i*(10 - k);
			if(sum%11 == 0)
			{
				if(i == 10)
				{
					printf("X\n");break;			
				}
				else
				{
					printf("%d\n",i);break;				
				}
			}
			sum = sum - i*(10 - k);
		}
		if(i == 10)
		{
			printf("-1\n");
		}		
	}

	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