POJ 2692 假币问题 解题报告

POJ 2692 假币问题 解题报告

编号:2692

 

考查点:枚举

 

思路:这道题需要枚举的变量少,从AL即可,不过我偏给它先优化了下,多此一举..。主要是判断是否符合轻或重的条件有点麻烦.

 

提交情况:不急不躁,不紧不慢,晃晃悠悠,晕晕乎乎的AC..

 

Source Code

 


//POJ Grids 2692
#include <string>
#include 
<string.h>
#include 
<iostream>
using namespace std;

char leftch[3][7= {0};
char rightch[3][7= {0};
string st[3];

bool flag[12];

bool light(char ch)
{
    
for (int i=0;i<3;i++)
    {
        
if (st[i]=="even")
            
continue;
        
switch (st[i][0])
        {
        
case 'u':
            
if (strchr(rightch[i],ch)==NULL)
                
return false;
            
break;
        
case 'd':
            
if (strchr(leftch[i],ch)==NULL)
                
return false;
            
break;
        }

    }
    
    
return true;
}

bool heavy(char ch)
{
    
for (int i=0;i<3;i++)
    {
        
if (st[i]=="even")
            
continue;
        
switch (st[i][0])
        {
        
case 'u':
            
if (strchr(leftch[i],ch)==NULL)
                
return false;
            
break;
        
case 'd':
            
if (strchr(rightch[i],ch)==NULL)
                
return false;
            
break;
        }

    }

    
return true;
}

int main()
{
    
int n;
    cin
>>n;
    
while (n--)
    {
        memset(leftch,
0,sizeof leftch);
        memset(rightch,
0,sizeof rightch);
        memset(flag,
0,sizeof flag);

        
for (int i=0;i<3;i++)
        {
            cin
>>leftch[i]>>rightch[i]>>st[i];
            
if (st[i]=="even")
            {
                
int len = strlen(leftch[i]);
                
for (int j=0;j<len;j++)
                {
                    flag[leftch[i][j]
-'A'= true;
                }
                len 
= strlen(rightch[i]);
                
for (int j=0;j<len;j++)
                {
                    flag[rightch[i][j]
-'A'= true;
                }
            }
        }

        
for (int i=0;i<12;i++)
        {
            
if (flag[i])
            {
                
continue;
            }
            
else
            {
                
char  ch = 'A'+i;
                
if (light(ch))
                {
                    cout
<<ch<<" is the counterfeit coin and it is light."<<endl;
                    
break;
                }
                
if (heavy(ch))
                {
                    cout
<<ch<<" is the counterfeit coin and it is heavy."<<endl;
                    
break;
                }
            }        
        }
    }

    
return 0;
}

总结:最近怎么没状态.是题难了还是我笨了?

 

 

 

                                                       By   Ns517

                                                      Time 09.02.03

posted @ 2009-02-03 19:47  端木  阅读(882)  评论(0编辑  收藏  举报