uva_340 - Master-Mind Hints
[cpp]
/**本题的意思是,对应相等的为强,不对应相等的为弱,
* 我的做法是每次比较时复制一个目标串,把他和输入的
*串对比,统计对应相等的,然后把值赋为-1,然后再统计不
*对应相等的
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
int cas, strong, week, *arr, *cmp, t, *arr1, n(0);
while(scanf("%d",&cas),cas){
printf("Game %d:\n", ++n);
arr = new int[cas+1]; cmp = new int[cas+1]; arr1 = new int[cas+1];
for(int i=0; i<cas; i++){
scanf("%d",&arr[i]);
}
while(true){
t = 0, strong = 0, week = 0;
for(int i=0; i<cas; i++){
scanf("%d",&cmp[i]);
arr1[i] = arr[i];
}
if(cmp[0]==0) break;
for(int i=0; i<cas; i++){
if(arr1[i]==cmp[i]){
strong++;
cmp[i]=-1; arr1[i] = -1;
} www.zzzyk.com
}
for(int i=0; i<cas; i++){
for(int j=0; j<cas; j++){
if(arr1[i]==cmp[j] && arr1[i]!=-1){
week++; cmp[j] = -1;
break;
}
}
}
printf(" (%d,%d)\n",strong, week);
}
}
return 0;
}
补充:软件开发 , C++ ,