"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
The first and only line of input contains a non-empty string ss consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only (|s|≤100|s|≤100) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
.BAC.
Yes
AA..CB
No
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
判断是否有在连续的三个位置ABC都出现;
#include "iostream"
#include "string"
using namespace std;
int main()
{
ios::sync_with_stdio(false);
string str;
cin>>str;
if(str.size()<3){cout<<"No"<<endl; return 0;}
for(int i=1;i<str.size()-1;i++)
if(str[i]!=str[i-1]&&str[i]!=str[i+1]&&str[i-1]!=str[i+1]&&str[i]!='.'&&str[i-1]!='.'&&str[i+1]!='.'){
cout<<"Yes"<<endl; return 0;
}
cout<<"No"<<endl;
return 0;
}
本文介绍了一个编程问题,即判断在给定的字符串中是否存在一种排列方式使得任意三个连续的位置上分别出现字符A、B、C。该问题通过简单的遍历算法解决,并提供了完整的代码示例。
764

被折叠的 条评论
为什么被折叠?



