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 0810311106 at 2009-08-23 19:07:52 on Problem 2498 and last updated at 2009-08-23 19:08:08
#include"stdio.h"
#include"string.h"
int main()
{
	int n,num=0;
	scanf("%d",&n);
	while(n--)
	{
		char a[10];
		int sum=0,p;
		int i,j;
		scanf("%s",&a);
		num++;
		for(i=1;i<=strlen(a);i++)
		{
			if(a[strlen(a)-i]=='?')
			{j=i;continue;}
			if(i%3==1)
			sum+=(a[strlen(a)-i]-'0')*9;
			else if(i%3==2)
			sum+=(a[strlen(a)-i]-'0')*3;
			else if(i%3==0)
			sum+=(a[strlen(a)-i]-'0')*7;
		}
		p=sum;
		for(i=0;i<=9;i++)
		{
			sum=p;
			if(j%3==1)
			{
				sum+=9*i;
				if(sum%10==0)
				break;
			}
			else if(j%3==2)
			{
				sum+=3*i;
				if(sum%10==0)
				break;
			}
			else if(j%3==0)
			{
				sum+=7*i;
				if(sum%10==0)
				break;
			}
		}
		a[strlen(a)-j]=i+'0';
		printf("Scenario #%d:\n",num);
		printf("%s\n\n",a);
	}
	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