uva 340

来源:互联网 发布:力度exp5000编程方法 编辑:程序博客网 时间:2024/05/16 10:44

题意下面这个博客讲得很清楚。

http://blog.163.com/kakarrot@yeah/blog/static/12011592520106241155854/


然后是我的代码:

#include<stdio.h>#include<string.h>#include<stdlib.h>int first[10000];int tem[10000];int other[10000];int main(){int i,j,n;int t=0;while(scanf("%d",&n)==1){if(n==0) break;for(i=0;i<n;i++){scanf("%d",&first[i]);tem[i]=first[i];}printf("Game %d:\n",++t);while(1){int a=0,b=0; int flag=0;for(i=0;i<n;i++){scanf("%d",&other[i]);if(i==0&&other[0]==0) flag=1;if(tem[i]==other[i]) {a++;tem[i]=0;other[i]=0;}}if(flag==1) break;for(i=0;i<n;i++){for(j=0;j<n;j++){if(tem[i]!=0&&other[j]!=0&&tem[i]==other[j]){b++;tem[i]=0;other[j]=0;}}}printf("    (%d,%d)\n",a,b);memset(other,0,sizeof(other));for(i=0;i<n;i++){tem[i]=first[i];}} }return 0;}

由于题目限制了出现的数字在1-9,同时每个数字只能比较一次,所以每比较一次就把那个数字置零就好。

0 0