题解 | #小易喜欢的单词#
小易喜欢的单词
http://www.nowcoder.com/practice/ca7b8af83e2f4ec1af2f23d6733223b5
//关于两个子序列条件找到4个索引位置,比较即可
#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;
int main(void)
{
string str;
cin>>str;
map<char,int> mp;
mp[str[0]]++;
int len = str.size();
int start1 = 0;
int end1 = len%2==0?len/2-1:len/2-1;
int start2 = len%2==0?len/2:len/2+1;
int end2 = len-1;
int one_1=-1;
int one_2=-1;
int two_1=-1;
int two_2=-1;
for(int i=start1;i<=end1;i++)
{
for(int j=start2;j<=end2;j++)
{
if(str[i]==str[j])
{
one_1=i;
two_1=j;
}
}
}
if(one_1!=-1&&two_1!=-1)
{
for(int i=end1;i>=start1;i--)
{
for(int j=end2;j>=start2;j--)
{
if(str[i]==str[j])
{
one_2=i;
two_2=j;
}
}
}
}
if(one_1>one_2&&two_1>two_2)
{
cout<<"Dislikes";
return 0;
}
for(int i=1;i<str.size();i++)
{
if(str[i]<'A'||str[i]>'Z')
{
cout<<"Dislikes";
return 0;
}
if(str[i]==str[i-1])
{
cout<<"Dislikes";
return 0;
}
mp[str[i]]++;
}
for(map<char,int>::iterator it=mp.begin();it!=mp.end();it++)
{
if(it->second>=4)
{
cout<<"Dislikes";
return 0;
}
}
cout<<"Likes";
return 0;
}