C++语言: Codee#25813
01 /*
02 +++++++++++++++++++++++++++++++++++++++
03 author: chm
04 +++++++++++++++++++++++++++++++++++++++
05 */
06
07 #include <map>
08 #include <set>
09 #include <list>
10 #include <queue>
11 #include <cmath>
12 #include <stack>
13 #include <bitset>
14 #include <cstdio>
15 #include <cctype>
16 #include <string>
17 #include <vector>
18 #include <cassert>
19 #include <cstdlib>
20 #include <cstring>
21 #include <fstream>
22 #include <sstream>
23 #include <iomanip>
24 #include <iostream>
25 #include <algorithm>
26
27 using namespace std;
28
29 FILE* fin = stdin;
30 FILE* fout = stdout;
31 const int max_size = 1000;
32
33 int ans[max_size];
34 int guess[max_size];
35 int flag[max_size];
36 int flag2[max_size];
37
38 int main()
39 {
40 #ifndef ONLINE_JUDGE
41 freopen("c:\\in.txt", "r", stdin);
42 fout = fopen("c:\\garage\\out.txt", "w");
43 #endif
44 int n;
45 int cnta, cntb;
46 int game = 1;
47 while(scanf("%d", &n) && n)
48 {
49 for(int j = 0; j < n; ++j) // read in answer
50 scanf("%d", &ans[j]);
51
52 fprintf(fout, "Game %d:\n", game++);
53 while(true) // get guess
54 {
55 cnta = cntb = 0;
56 memset(flag, 0, sizeof(flag)); // the table of answer array
57 memset(flag2, 0, sizeof(flag2)); // the table of guess array
58
59 for(int j = 0; j < n; ++j) // in situation a
60 {
61 scanf("%d", &guess[j]);
62 if(guess[j] == ans[j])
63 {
64 flag2[j] = flag[j] = 1;
65 ++cnta;
66 }
67 }
68 for(int j = 0; j < n; ++j)
69 if(flag2[j] == 0) // not in situation a
70 for(int k = 0; k < n; ++k) // find the first match digit
71 if(flag2[j] == 0
72 && flag[k] == 0
73 && guess[j] == ans[k])
74 {
75 flag2[j] = flag[k] = 1;
76 ++cntb;
77 }
78 if(!guess[0]) // the end of a set
79 break;
80 fprintf(fout, " (%d,%d)\n", cnta, cntb);
81 }
82 }
83
84
85 #ifndef ONLINE_JUDGE
86 fclose(fout);
87 system("c:\\garage\\check.exe");
88 system("notepad c:\\garage\\out.txt");
89 #endif
90 return 0;
91 }
02 +++++++++++++++++++++++++++++++++++++++
03 author: chm
04 +++++++++++++++++++++++++++++++++++++++
05 */
06
07 #include <map>
08 #include <set>
09 #include <list>
10 #include <queue>
11 #include <cmath>
12 #include <stack>
13 #include <bitset>
14 #include <cstdio>
15 #include <cctype>
16 #include <string>
17 #include <vector>
18 #include <cassert>
19 #include <cstdlib>
20 #include <cstring>
21 #include <fstream>
22 #include <sstream>
23 #include <iomanip>
24 #include <iostream>
25 #include <algorithm>
26
27 using namespace std;
28
29 FILE* fin = stdin;
30 FILE* fout = stdout;
31 const int max_size = 1000;
32
33 int ans[max_size];
34 int guess[max_size];
35 int flag[max_size];
36 int flag2[max_size];
37
38 int main()
39 {
40 #ifndef ONLINE_JUDGE
41 freopen("c:\\in.txt", "r", stdin);
42 fout = fopen("c:\\garage\\out.txt", "w");
43 #endif
44 int n;
45 int cnta, cntb;
46 int game = 1;
47 while(scanf("%d", &n) && n)
48 {
49 for(int j = 0; j < n; ++j) // read in answer
50 scanf("%d", &ans[j]);
51
52 fprintf(fout, "Game %d:\n", game++);
53 while(true) // get guess
54 {
55 cnta = cntb = 0;
56 memset(flag, 0, sizeof(flag)); // the table of answer array
57 memset(flag2, 0, sizeof(flag2)); // the table of guess array
58
59 for(int j = 0; j < n; ++j) // in situation a
60 {
61 scanf("%d", &guess[j]);
62 if(guess[j] == ans[j])
63 {
64 flag2[j] = flag[j] = 1;
65 ++cnta;
66 }
67 }
68 for(int j = 0; j < n; ++j)
69 if(flag2[j] == 0) // not in situation a
70 for(int k = 0; k < n; ++k) // find the first match digit
71 if(flag2[j] == 0
72 && flag[k] == 0
73 && guess[j] == ans[k])
74 {
75 flag2[j] = flag[k] = 1;
76 ++cntb;
77 }
78 if(!guess[0]) // the end of a set
79 break;
80 fprintf(fout, " (%d,%d)\n", cnta, cntb);
81 }
82 }
83
84
85 #ifndef ONLINE_JUDGE
86 fclose(fout);
87 system("c:\\garage\\check.exe");
88 system("notepad c:\\garage\\out.txt");
89 #endif
90 return 0;
91 }