网易:小易喜欢的单词

题目链接:小易喜欢的单词

第一种做法:

直接对三种情况暴力判断

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	bool judge1(string s);
	bool judge2(string s);
	bool judge3(string s);	 
	string str;
	while(cin>>str)
	{
		if(judge1(str) && judge2(str) && judge3(str))
		{
			cout<<"Likes"<<endl; 
		}else cout<<"Dislikes"<<endl;
	}
	
	return 0;
}
bool judge1(string s)
{
	for(int i=0;i<s.length();++i)
	{
		if(s[i]-'A'<0 || s[i]-'A'>=26) return false; 
	}	
	return true;
}
bool judge2(string s)
{
	for(int i=0;i<s.length()-1;++i)
	{
		if(s[i]==s[i+1]) return false;
	}
	return true;
}
bool judge3(string s)
{
	for(int x1=0;x1<s.length();++x1)
	{
		for(int y1=x1+1;y1<s.length();++y1)
		{
			for(int x2=y1+1;x2<s.length();++x2)
			{
				for(int y2=x2+1;y2<s.length();++y2)
				{
					if(s[x1]==s[x2] && s[y1]==s[y2])
					{
						return false;
					}
				}
			}
		}		
	}
	return true;
}


第二种做法:

明天做

猜你喜欢

转载自blog.csdn.net/q1122333/article/details/82847844