当前位置: 代码迷 >> 综合 >> Master-Mind Hints UVA - 340
  详细解决方案

Master-Mind Hints UVA - 340

热度:88   发布时间:2023-10-13 15:06:54.0

问题类型:计数,字符串。

03pie’s solution for [UVA-340]:

#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<string>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<ctime>
#include<vector>
#include<fstream>
#include<list>
using namespace std;#define ms(s) memset(s,0,sizeof(s))typedef unsigned long long ULL;
typedef long long LL;const double PI = 3.141592653589;
const int INF = 0x3fffffff;#define maxn 1010int main(){
// freopen("F://inp.txt","r",stdin);int n, a[maxn],b[maxn];int kase=0;while(scanf("%d",&n)==1&&n){printf("Game %d:\n",++kase) ;for(int i=0;i<n;i++){scanf("%d",&a[i]);}for(;;){int A=0,B=0;for(int i=0;i<n;i++)        {scanf("%d",&b[i]);if(b[i]==a[i])A++;}if(b[0]==0) break;for(int d=1;d<=9;d++){int c1=0,c2=0;for(int i=0;i<n;i++){if(a[i]==d) c1++;if(b[i]==d) c2++;}B+=(c1<=c2?c1:c2);//包含相同数字,也就是说只要都出现过就有记录 }printf(" (%d,%d)\n",A,B-A);}}return 0;
}   
  相关解决方案