P.S. 每用掉一個數字就把它記錄下來,以避免重複判斷的狀況發生。
[C](0.020)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int main() | |
{ | |
int N, game = 1; | |
while( scanf( "%d", &N ) != EOF && N != 0 ) | |
{ | |
printf( "Game %d:\n", game++ ); | |
int s[1005], g[1005]; | |
int i, j; | |
for( i = 0 ; i < N ; i++ ) | |
scanf( "%d", &s[i] ); | |
int exit = 1; | |
while(1) | |
{ | |
int position_g[1005] = {0}, position_s[1005] = {0}; | |
int A = 0, B = 0; | |
for( i = 0 ; i < N ; i++ ) | |
{ | |
scanf( "%d", &g[i] ); | |
if( g[i] == s[i] ) | |
{ | |
A++; | |
position_s[i] = 1; | |
position_g[i] = 1; | |
} | |
if( g[i] ) | |
exit = 0; | |
} | |
if( exit ) | |
break; | |
exit = 1; | |
for( i = 0 ; i < N ; i++ ) | |
{ | |
if( position_g[i] ) | |
continue; | |
for( j = 0 ; j < N ; j++ ) | |
{ | |
if( position_s[j] ) | |
continue; | |
if( i == j ) | |
continue; | |
if( (g[i] == s[j]) ) | |
{ | |
B++; | |
position_s[j] = 1; | |
position_g[i] = 1; | |
break; | |
} | |
} | |
} | |
printf( " (%d,%d)\n", A, B ); | |
} | |
} | |
return 0; | |
} |
0 意見:
張貼留言