Codeforces Round #487 (Div. 2) A. A Blend of Springtime

A. A Blend of Springtime
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
When the curtains are opened, a canvas unfolds outside. Kanno marvels at all the blonde colours along the riverside — not tangerines, but blossoms instead.

"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.

Input

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

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).

Examples
input
Copy
.BAC.
output
Copy
Yes
input
Copy
AA..CB
output
Copy
No
Note

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.

題意:有三種顏色的花瓣a,b,c,每種花瓣脫落時會讓其兩邊的花瓣染上它的顏色,問最後全部脫落完有沒有一個花瓣有三種顏色

題解:暴力,遍歷一遍,i-1,i,i+1,不一樣時存在答案

代碼:

#include <bits/stdc++.h>
using namespace std;
const int M = 1e6+10;
string s;

int main()
{
    cin>>s;
    int p=0;
    for(int i=1;i<s.length()-1;i++)
    {
        if(s[i]=='A')
        {
            if((s[i-1]=='B'&&s[i+1]=='C')||(s[i-1]=='C'&&s[i+1]=='B'))
            {
                p=1;
                break;
            }
        }
        else if(s[i]=='B')
        {
            if((s[i-1]=='A'&&s[i+1]=='C')||(s[i-1]=='C'&&s[i+1]=='A'))
            {
                p=1;
                break;
            }
        }
        else if(s[i]=='C')
        {
            if((s[i-1]=='B'&&s[i+1]=='A')||(s[i-1]=='A'&&s[i+1]=='B'))
            {
                p=1;
                break;
            }
        }
    }
    if(p)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章