這和以前常玩的 _A_B 猜數字一樣
只不過可以重複猜同樣的數字
所以檢查時也要特別注意
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <cstdio>
//#include <cstring>
//#include <iostream>
using namespace std;
int main(){
freopen("input.txt","r",stdin);
int n;
int game_num = 1;
while(scanf("%d",&n)!=EOF){
if(n==0)break;
printf("Game %d:\n", game_num++); // print game number
int s[n]; memset(s,0,sizeof(s)); //Secret code
for(int i=0;i<n;i++)scanf("%d",&s[i]); //Input secret code
int g[n]; memset(g,0,sizeof(g)); //Guess code
while(1){
int check[n]; //檢查用的陣列,和s陣列相同
for(int i=0;i<n;i++)check[i]=s[i]; //檢查用的陣列
for(int i=0;i<n;i++)scanf("%d",&g[i]); //Input guess code
if(g[0]==0)break;
int a=0,b=0; // hint a and b, (a,b)
for(int i=0;i<n;i++)
if(g[i]==check[i]){
a++;
check[i]=0;
g[i]=0;
}
for(int i=0;i<n;i++)
for(int j=0;j<n;j++){
if(g[i]==check[j] && g[i]!=0){
b++;
check[j]=0;
g[i]=0;
}
}
printf(" (%d,%d)\n",a,b);
}
//for(int i=0;i<n;i++)
// printf("%d ",s[i]);
//printf("\n");
}
return 0;
}
沒有留言:
發佈留言