# 麻烦+找规律+各种情况

E - E
Time Limit:2000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u

Description

Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:

• take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color;
• take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color.

She repeats this process until there is only one card left. What are the possible colors for the final card?

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200) — the total number of cards.

The next line contains a string s of lengthn — the colors of the cards. s contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively.

Output

Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order.

Sample Input

Input
`2RB`
Output
`G`
Input
`3GRG`
Output
`BR`
Input
`5BBBBB`
Output
`B`

Hint

In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.

In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card.

In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards.

题意：有n张卡片，颜色有B，G，R三种，两张不动颜色的卡片合成一张第三种颜色的卡片，两张相同颜色的卡片合成该颜色的一张卡片。  按照此规则，任意组合，输出最后一张卡片的颜色，输出所有可能。

1.当n张卡片只有一种颜色，最后一张肯定就是该颜色。

2.当n（n>2）张卡片里有两种颜色，A有（n-1）张，B只有1张，那么结果可以为B，C两种颜色。

3.当n==2，且有A，B颜色卡片各一张，则最后颜色为C颜色。

4.其他情况均有A，B，C这三种颜色。

`#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){    int n;    char str[220];    int sum[3];    while(scanf("%d",&n)!=EOF)    {        memset(str,0,sizeof(str));        scanf("%s",str);        if(n==1)        {            printf("%c\n",str[0]);            continue;        }        memset(sum,0,sizeof(sum));        for(int i=0;i<n;i++)        {            if(str[i]=='B')                sum[0]++;            else if(str[i]=='G')                sum[1]++;            else                  sum[2]++;        }if(sum[0]>=1&&sum[1]==0&&sum[2]==0)//BBBBB {printf("B\n");}else if(sum[1]>=1&&sum[0]==0&&sum[2]==0)//GGGGG{printf("G\n");}else if(sum[2]>=1&&sum[1]==0&&sum[0]==0)////RRRRR{printf("R\n");}else if(sum[0]==1&&sum[1]==1&&sum[2]==0)//BG{printf("R\n");}else if(sum[0]==1&&sum[1]==0&&sum[2]==1)//BR{printf("G\n");}else if(sum[0]==0&&sum[1]==1&&sum[2]==1)//GR{printf("B\n");}else {if(sum[0]>1){if(sum[1]==1&&sum[2]==0)printf("GR\n");else if(sum[1]==0&&sum[2]==1)printf("GR\n");elseprintf("BGR\n");}else if(sum[1]>1){if(sum[0]==1&&sum[2]==0)printf("BR\n");else if(sum[0]==0&&sum[2]==1)printf("BR\n");else     printf("BGR\n");}else if(sum[2]>1){if(sum[0]==1&&sum[1]==0)printf("BG\n");else if(sum[0]==0&&sum[1]==1)printf("BG\n");else printf("BGR\n");}elseprintf("BGR\n");}    }return 0;}`

0 0