九度[1150]Counterfeit Dollar

# include<iostream>
# include<string>
# include<cstdio>
using namespace std;
struct node{
	string a;
	string b;
}s[3];
int main()
{
	string a[3];
	int n=0;
	bool heavy;
	char c;
	//freopen("in.txt","r",stdin);
	cin>>n;
	while(n--)
	{
		for(int i=0;i<3;i++)
		{
			cin>>s[i].a>>s[i].b>>a[i];
		}
		bool isFind=false;
		for(int i=0;i<12;i++)
		{
			c='A'+i;
			heavy=true;
			for(int j=0;j<3;j++)
			{
				if((s[j].a.find(c)!=-1) || s[j].b.find(c)!=-1) //在里面 
				{
					if(a[j]=="even")
					{
						isFind=false;
						break;
					}
					if(a[j]=="up")
					{
						if(s[j].a.find(c)>=0)
						{
							isFind=true;
							heavy=true;
							continue;
						}
						else
						{
							isFind=true;
							heavy=false;
							continue;
						}
					}
					else
					{
						if(s[j].a.find(c)>=0)
						{
							isFind=true;
							heavy=false;
							continue;
						}
						else
						{
							isFind=true;
							heavy=true;
							continue;
						}
					}
				}
				else if((s[j].a.find(c)==-1) || s[j].b.find(c)==-1) //不在里面
				{
					if(a[j]!="even")
					{
						isFind=false;
						break;
					}
				}
			}
			if(isFind ) break;
		}
		cout<<c<<" is the counterfeit coin and it is ";
		if(heavy)
			cout<<"heavy."<<endl;
		else 
			cout<<"light."<<endl;
	}
	//system("pause");
	return 0;
}

  要注意的地方就是s[i].a.find(c)>=0  是不对的 可以先赋值再比较 也可以改成!=-1  切记切记 或者用string::npos

posted @ 2016-02-20 22:42  dreamer123  阅读(181)  评论(0编辑  收藏  举报