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 125019682 at 2006-04-18 18:17:18 on Problem 2498
#include <iostream>
#include <string>
using namespace std;

void main()
{
	string ID;
	int a, i, j,c,d,n, product;
	int factors1[ 7 ] = {9, 7, 3, 9, 7, 3, 9}, factors2[ 6 ] = { 7, 3, 9, 7, 3, 9 };
	
	cin >> n;
	
	for ( int e = 1; e <= n; e++ )
	{
		cin >> ID;
		cout << "Scenario #" << e << ":" << endl;
		a = ID.length();
		if ( a == 7)
		{
			for ( i = 0; i < a; i++ )
			{
				if ( ID[ i ] == 63 )
				{
					c = i;
				    continue;
				}
				product += ( ID[ i ] - 48) * factors1[ i ];
				d = product;
			}
			for ( j = 0; j <= 9; j++ )
			{
				product = d;
				product += j * factors1[ c ];
				if ( product % 10 == 0 )
				{
					ID [ c ] = j + 48;
					break;
				}
			}
			for ( i = 0;  i < a; i++ )//h--i
				cout << ID[ i ];
			cout << endl << endl;
			continue;
		}
		else
		{
			for (  i = 0; i < a; i++ )
			{
				if ( ID[ i ] == 63 )
				{
					c = i;
					continue;
				}
				product += ( ID[ i ] - 48 ) * factors2[ i ];
				d = product;
			}
			for  ( j = 0; j <= 9; j++ )
			{
				product = d;
				product += j * factors2[ c ];
				if ( product % 10 == 0)
				{
					ID[ c ] = j + 48;
					break;
				}
			}
			for ( i = 0; i < a; i++ ) 
				cout << ID[ i ];
			cout << endl << endl;

		}
			
	}
	
}

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