340 - Master-Mind Hints

340 - Master-Mind Hints


题目大意:计算列相同的数相同的个数,和不同的列相同的数,注意输出格式;


解题思路:计算相同的数的对数,减去相同列的数相同的对数,剩下就是不同列的相同数的对数。


#include<stdio.h>
#include<string.h>

const int N = 1005;
int s[N], s1[N];
int n, d[N], t = 0;
int count, count1;
int main() {
	
	int i, j;
	while (scanf("%d", &n) == 1 && n) {
		t++;
		for( i = 0; i < n; i++) {

			scanf("%d", &s[i]);
		}

		printf("Game %d:\n", t);

		while(1) {

			for( j = 0; j < n ; j++) {

				scanf("%d", &s1[j]);
			}
			
			if(s1[0] == 0)
				break;

			count = count1 = 0;
			for( i = 0; i < n; i++) {

				if(s1[i] == s[i])
					count++;
			}
			for(i = 0; i < n; i++)
				for (j = 0; j < n; j++ ) {
					
					if(s[i] == s1[j]  && s1[j]) {
						s1[j] = 0;
						count1++;
						break;
					}
				}

			count1 -= count;
		printf("    (%d,%d)\n", count, count1);

		}
		
	}
	return 0;

}




你可能感兴趣的:(340 - Master-Mind Hints)