麻烦+找规律+各种情况

来源:互联网 发布:mm下载软件 编辑:程序博客网 时间:2024/03/28 20:04

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

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
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 森林里树没了动物怎么办 森林联机卡了怎么办 iphone日历删了怎么办 空调遥控开不了怎么办 华为平板充电慢怎么办 卡贴机网速很慢怎么办 苹果手机wifi慢怎么办 苹果wifi网速慢怎么办 苹果下载app慢怎么办 苹果手机突然很难充进电怎么办 winsxs误删了怎么办 cad打开有问号怎么办 网络连接超时怎么办 宽带 绝地求生很卡怎么办 吃鸡更新错误怎么办 iac账号封号了怎么办 凭证号不连续怎么办 我的世界延迟怎么办 黄金棒打不开怎么办 枪火游侠黑屏怎么办 老虎直播封了怎么办 网卡及驱动异常怎么办 电脑刺激战场卡怎么办 grub 文件兼容性错误怎么办 电脑程序不兼容怎么办 运行程序不兼容怎么办 usb驱动删了怎么办 电脑卡死 点不开怎么办 电脑开机找不到驱动程序怎么办 显卡关了黑屏怎么办 xp全部程序打不开怎么办 七彩凤电脑打不开怎么办 鹦鹉鱼不敢吃食怎么办 甘油三酯1.87怎么办 手机移动数据网打不开怎么办 苹果手机浏览器打不开没网怎么办 玩多人游戏很紧张怎么办 dnf容易掉线怎么办 qq名字改不了怎么办 手被打火机烧伤怎么办 无效的菜单句柄怎么办