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 20083331 at 2009-04-30 21:44:48 on Problem 2498
#include<iostream>
#include<cstring>

using namespace std;

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		char record[9]={0};
		cin>>record;
		int len=strlen(record);
		int sum=0,sign;
		for(int j=len-1;j>=0;j--)
		{
			if(record[j]!='?' && (j==len-1 || j==len-4 || j==len-7))
			{
				sum+=(record[j]-'0')*9;
			}
			else if(record[j]!='?' && (j==len-2 || j==len-5 || j==len-8))
			{	
				sum+=(record[j]-'0')*3;
			}
			else if(record[j]!='?' && (j==len-3 || j==len-6 || j==len-9))
			{	
				sum+=(record[j]-'0')*7;

			}
			else
				sign=j;
		}
		for(int k=0;k<=9;k++)
		{
			int temp=sum;
			if(sign==len-1 || sign==len-4 || sign==len-7)
				temp+=k*9;
			else if(sign==len-2 || sign==len-5 || sign==len-8)
				temp+=k*3;
			else if(sign==len-3 || sign==len-6 || sign==len-9)
				temp+= k*7;
			
			if(temp%10==0)
			{
				record[sign]=k+'0';
				break;
			}
		}
		cout<<"Scenario #"<<i+1<<":"<<endl;
		cout<<record<<endl;
		cout<<endl;
	}

	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