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

注意10只能在最后一位

Posted by mickeyandkaka at 2010-11-13 22:31:34 on Problem 2190
注意10只能在最后一位 10在其他位数时输出为-1 测试数据时会测试到 太恶心了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include <stdio.h>
int main()
{
	char str[10],a[10];
	int i,s=0,t;
	gets(str);
 	for(i=9;i>=0;i--)
		a[i]=str[9-i];
	for(i=0;i<10;i++)
	{
		if(a[i]=='X')
			s+=10;
		if(a[i]>='0'&&a[i]<='9')
			s+=(i+1)*(a[i]-48);
		if(a[i]=='?')
			t=i;
	}
	for(i=0;i<=10;i++)
	{
		if(!((s+(t+1)*i)%11))
		{
			s+=(t+1)*i;
			break;	
		}	
	}
	if(i==10&&t==0)
	printf("X");
	else if(i>=0&&i<=9)	
	printf("%d",i);
	else
	printf("-1");
	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