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

好心人帮帮忙谢谢了~~为什么老是WA???

Posted by anyunhua at 2007-05-18 22:15:43 on Problem 2498
#include<iostream.h>

int main()
{
	int a[7]={9,7,3,9,7,3,9};
	int b[6]={7,3,9,7,3,9};
	char c[8];
	long int n,i=0,j,m,q,k,sum=0;
	cin>>n;
	while(i<n)
	{
		cin>>c;
		for(j=0;j<8;j++)
		{
			if(c[j]=='?')
				q=j;
				 
			if(c[j]==0)
			{	m=j;break;}
		}
		
		if(m==7)
		{
			for(j=0;j<7;j++)
			{	if(c[j]=='?')continue;
				sum+=a[j]*(c[j]-'0');
			}
		
				
				if(q==0||q==3||q==6)
				{		for(k=0;;k++)
					if((sum+9*k)%10==0)
					{	
						c[q]=k+'0';break;
					}
				}
				if(q==1||q==4)
				{		for(k=0;;k++)
					if((sum+7*k)%10==0)
					{	
						c[q]=k+'0';break;
					}
				}
				if(q==2||q==4)
				{		for(k=0;;k++)
					if((sum+3*k)%10==0)
					{	
						c[q]=k+'0';break;
					}
				}

					
			
			sum=0;
		}
		if(m==6)
		{
			for(j=0;j<6;j++)
			{	if(c[j]=='?')continue;
				sum+=b[j]*(c[j]-'0');
			}
			
				
				if(q==0||q==3)
				
				{	for(k=0;;k++)
					if((sum+7*k)%10==0)
					{	c[q]=k+'0';break;}
				}
				if(q==1||q==4)
				{	for(k=0;;k++)
					if((sum+3*k)%10==0)
					{
				
						c[q]=k+'0';break;
					}
				}
				if(q==2||q==5)
				{	for(k=0;;k++)
					if((sum+9*k)%10==0)
					{
				
						c[q]=k+'0';break;
					}
				}

					
			
			sum=0;
		}
		cout<<"Scenario #"<<i+1<<":"<<endl;
		cout<<c<<endl<<endl;

	
		i++;

				
	}
	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