| Run ID | User | Problem | Result | Memory | Time | Language | Code Length | Submit Time |
| 6624780 | kingpro | 1013 | Accepted | 240K | 0MS | C++ | 1262B | 2010-03-25 04:19:54 |
PKU 1013 Counterfeit Dollar
1 #include <iostream>
2 using std::cin;
3 using std::cout;
4 using std::endl;
5 char left[3][7]={0}, right[3][7]={0}, result[3][5]={0};
6
7 bool isLight(char c)
8 {
9 for(int i=0; i<3; i++)
10 {
11 switch(result[i][0])
12 {
13 case 'e':
14 if(strchr(left[i], c)!=NULL || strchr(right[i], c)!=NULL)
15 return false;
16 break;
17 case 'u':
18 if(strchr(right[i], c)==NULL)
19 return false;
20 break;
21 case 'd':
22 if(strchr(left[i], c)==NULL)
23 return false;
24 break;
25 }
26 }
27 return true;
28 }
29 bool isHeavy(char c)
30 {
31 for(int i=0; i<3; i++)
32 {
33 switch(result[i][0])
34 {
35 case 'e':
36 if(strchr(left[i], c)!=NULL || strchr(right[i], c)!=NULL)
37 return false;
38 break;
39 case 'u':
40 if(strchr(left[i], c)==NULL)
41 return false;
42 break;
43 case 'd':
44 if(strchr(right[i], c)==NULL)
45 return false;
46 break;
47 }
48 }
49 return true;
50 }
51 int main()
52 {
53 int i=0;
54 cin>>i;
55 while(i--)
56 {
57 for(int i=0; i<3; i++)
58 cin>>left[i]>>right[i]>>result[i];
59 for(char c='A';c<='L'; c++)
60 {
61 if(isLight(c))
62 {
63 cout<<c<<" is the counterfeit coin and it is light."<<endl;
64 break;
65 }
66 if(isHeavy(c))
67 {
68 cout<<c<<" is the counterfeit coin and it is heavy."<<endl;
69 break;
70 }
71 }
72 }
73 return 0;
74 }
这个 称球的问题...12个小球有一个重量不一样 称三次确定是哪个小球 不用程序我倒是会解 这个逻辑复杂...
我承认这道题我是看了别人的代码的 有没有高人解释下...
Author: CriusWuBlog: http://kingpro.cnblogs.comContact: kingpro@live.cn
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

posted on
浙公网安备 33010602011771号