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 zjp at 2009-08-23 11:05:55 on Problem 2498
#include <stdio.h>
#include <string.h>
   int main ()
   {
   	char str[10];
   	int num[10];
   	int u;
   	int i;
   	int x;
   	int sum;
	int j=1;
   	  int n;int len;
   	  scanf ("%d",&n);
   	  while (n--)
   	  { int flag=1;
		  sum=0;
   	  	scanf("%s",str);
   	  	len=strlen(str);
   	  	for(i=len;i>=1;i--)
   	  	{ 
   	  		 if (flag%3==1)
   	  	  num[i]=9;
   	  	  if (flag%3==2)
   	  	  	num[i]=3;
   	  	  	if (flag%3==0)
   	  	  		num[i]=7;
			flag++;
   	  	}
   	  for (i=0;i<len;i++)
   	   {  if (str[i]=='?')
	  {x=num[i+1];}
   	     else 
   	     		sum=sum+(str[i]-'0')*num[i+1];
   	   }  	
   	  	for (i=0;i<=9;i++)
   	  	  {if ((sum+x*i)%10==0)
   	  	  	{u=i;
   	  	     break;}
   	  	  }
    
printf("Scenario #%d:\n",j);
    	for (i=0;i<len;i++)
   	  {	if (str[i]!='?')
   	  	printf("%c",str[i]);
   	  	else 
   	  	printf("%d",u);}
   	  	printf("\n\n");
		j++;
   	  		
   	  	}
   	
   	
   	
   	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