340 - Master-Mind Hints

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 }

转载于:https://www.cnblogs.com/invisible/archive/2012/03/14/2396072.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值