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

众位兄弟姐妹帮看看吧,我都快没语言了,save me!!!

Posted by LeonGemini at 2005-03-16 23:31:07 on Problem 1013
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int judge( char );
int weigh( char );

char left[3][7], right[3][7], bal[3][5];

int main()
{
   int times;
   char result[500][2];
   
   cin >> times;
	
   for ( int k = 0; k < times; k++ ) {
	  
      for ( int i = 0; i < 3; i++ ) 
		 cin >> left[i] >> right[i] >> bal[i];

	  char coin;
      for ( coin = 'A'; coin <= 'L'; coin++ ) {
		 int bad = judge( coin );
		 if ( bad == 1 )
			break;
		 
	  }
	  result[k][0] = coin;

	  int weight = weigh( coin );
	  result[k][1] = weight;

   }

   for ( k =0; k < times; k++ ) {
      if ( result[k][1] == 2 )
		 cout << result[k][0] << " is the counterfeit coin and it is heavy." << endl;
	  else
		 cout << result[k][0] << " is the counterfeit coin and it is light." << endl;
   }

   return 0;

}
		 

int judge( char c )
{
   int x = 1;
   for ( int i = 0; i < 3; i++ ) {
      for ( int j = 0; j < strlen( left[i] ); j++ ) {
		 if ( ( c == left[i][j] || c == right[i][j] ) && bal[i][0] == 'e' ) {
            x = 0;
			break;
		 }
		 else {
			if ( c != left[i][j] && c != right[i][j] && bal[i][0] != 'e' ) {
			   x = 0;
			   break;
			}
		 }
	  }
   }
   return x;
}


int weigh( char c )
{
   int y = 2;
   for ( int i = 0; i < 3; i++ ) {
	  if ( bal[i][0] == 'u' ) {
		 for ( int j = 0; j < strlen( left[i] ); j++ ) {
			if ( c == left[i][j] )
			   y = 2;
			if ( c == right[i][j] )
			   y = 1;
			else
			   break;
		 }
	  }
	  if ( bal[i][0] == 'd' ) {
		 for ( int j = 0; j < strlen( left[i] ); j++ ) {
			if ( c == left[i][j] )
			   y = 1;
			if ( c == right[i][j] )
			   y = 2;
			else
			   break;
		 }
	  }
	  else
		 break;
   }
   return y;
}

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