UVA 340 (暑假-排序、检索 -A - Master-Mind Hints)

#include <stdio.h> 
#include <string.h> 
int main() {
	const int Max = 1050;
	int str_1[Max], str_2[Max], str_3[Max];
	int t = 1, n;
	while (scanf("%d", &n), n) {
		//getchar();
		printf("Game %d:\n", t++);
	//	gets(str_1);
		for (int i = 0; i < n; i++)
			scanf("%d", &str_1[i]);

//		puts(str_1);
		while (1) {
			for (int i = 0; i < n; i++)
				scanf("%d", &str_2[i]);
			if (str_2[0] == 0)
				break;
//			puts(str_2);
			memset(str_3, 0, sizeof(str_3));

			int count_1 = 0, count_2 = 0;
			for (int i = 0; i < n; i++)
				if (str_1[i] == str_2[i])
					count_1++, str_3[i] = 1, str_2[i] = -1; 

			for (int i = 0; i < n; i++) {	
				if (str_3[i] == 1)
					continue;
				for (int j = 0; j < n; j++) {
					if (str_2[j] == -1)
						continue;
					else if (str_1[i] == str_2[j]) {
						str_2[j] = -1, count_2++; //printf("%c  count_2 = %d",str_2[j], count_2);
						break;
					}
				}

			}
			printf("    (%d,%d)\n", count_1, count_2);
		}
	}
	return 0;
}

你可能感兴趣的:(UVA 340 (暑假-排序、检索 -A - Master-Mind Hints))