You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
# define maxn 1010
int main ( void ) {
int n , i , j , k = 0 ;
int a [ maxn ] , b [ maxn ] ;
while ( scanf ( " %d " , & n ) = = 1 & & n ) //n=0时输入结束
{
printf ( " Game %d: \n " , + + k ) ;
for ( i = 0 ; i < n ; i + + ) scanf ( " %d " , & a [ i ] ) ;
while ( 1 ) //可改为for(;;)
{
int A = 0 , B = 0 , count = 0 ;
for ( i = 0 ; i < n ; i + + ) {
scanf ( " %d " , & b [ i ] ) ;
if ( a [ i ] = = b [ i ] ) A + + ;
if ( b [ i ] = = 0 ) count + + ; //统计输入0的个数
}
if ( count = = n ) break ; //如果四位数皆为零,则输入结束
for ( j = 0 ; j < = 9 ; j + + ) {
int a1 = 0 , a2 = 0 ; //统计数字j在答案序列和猜测序列中各出现多少次数
for ( i = 0 ; i < n ; i + + ) {
if ( a [ i ] = = j ) a1 + + ; //统计a[i]、b[i]中j的个数
if ( b [ i ] = = j ) a2 + + ;
}
if ( a1 < a2 ) B = B + a1 ; //记统计的最小的个数 即为序列拥有相同元素的个数
else B = B + a2 ;
}
printf ( " (%d,%d) \n " , A , B - A ) ; //B减去相同位置的个数A, 即为元素相同, 但位置不同的个数
}
}
}