time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 length n — 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.

Examples
Input
2
RB
Output
G
Input
3
GRG
Output
BR
Input
5
BBBBB
Output
B
Note

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.

题意就是两种颜色不同的牌合成一个第三种颜色的牌,两种颜色相同的就合成该颜色的牌,问最后可能的颜色是什么。

要注意一点就是要按字母顺序输出,就是wa在这里了。。。

有以下几种情况:

1.只有一张牌,最后就是这张牌的颜色。

2.两张牌,都是同一种颜色就直接输出了,如果不同就是第三种牌的颜色。

3.多张牌(>2)

1)都是同一种颜色就直接输出了。

2)如果除了一张牌颜色不一样,其他的牌都是一种颜色,最后输出的结果就是这一张牌的颜色和第三种颜色。

3)如果颜色都有或者只有两种颜色,但是每一种颜色的牌数>1,结果就是三种颜色都输出。

要按字母顺序输出!!!

代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
char str[250];
int n,b,r,g;
while(~scanf("%d",&n)){
scanf("%s",&str);
b=0;r=0;g=0;
if(n==1) printf("%c\n",str[0]);
else if(n==2){
if(str[0]=='B'&&str[1]=='B') printf("B\n");
else if(str[0]=='G'&&str[1]=='G') printf("G\n");
else if(str[0]=='R'&&str[1]=='R') printf("R\n");
else{
if((str[0]=='B'||str[0]=='G')&&(str[1]=='B'||str[1]=='G')) printf("R\n");
else if((str[0]=='B'||str[0]=='R')&&(str[1]=='B'||str[1]=='R')) printf("G\n");
else if((str[0]=='G'||str[0]=='R')&&(str[1]=='G'||str[1]=='R')) printf("B\n");
}
}
else{
for(int i=0;i<n;i++){
if(str[i]=='B') b++;
if(str[i]=='G') g++;
if(str[i]=='R') r++;
}
if(b==n) printf("B\n");
else if(r==n) printf("R\n");
else if(g==n) printf("G\n");
else if(b+g==n&&b>g&&g==1) printf("GR\n");
else if(b+g==n&&b<g&&b==1) printf("BR\n");
else if(b+r==n&&b>r&&r==1) printf("GR\n");
else if(b+r==n&&b<r&&b==1) printf("BG\n");
else if(g+r==n&&g>r&&r==1) printf("BR\n");
else if(g+r==n&&g<r&&g==1) printf("BG\n");
else printf("BGR\n");
}
}
return 0;
}

Codeforces 626 B. Cards (8VC Venture Cup 2016-Elimination Round)的更多相关文章

  1. 8VC Venture Cup 2016 - Elimination Round B. Cards 瞎搞

    B. Cards 题目连接: http://www.codeforces.com/contest/626/problem/B Description Catherine has a deck of n ...

  2. codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre

    C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + ...

  3. Codeforces 8VC Venture Cup 2016 - Elimination Round F. Group Projects 差分DP*****

    F. Group Projects   There are n students in a class working on group projects. The students will div ...

  4. 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)

    题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...

  5. 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树

    G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...

  6. 8VC Venture Cup 2016 - Elimination Round F. Group Projects dp

    F. Group Projects 题目连接: http://www.codeforces.com/contest/626/problem/F Description There are n stud ...

  7. 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分

    E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...

  8. 8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力

    D. Jerry's Protest 题目连接: http://www.codeforces.com/contest/626/problem/D Description Andrew and Jerr ...

  9. 8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分

    C. Block Towers 题目连接: http://www.codeforces.com/contest/626/problem/C Description Students in a clas ...

随机推荐

  1. arc068 E: Snuke Line

    首先要知道 (m/1 + m/2 + ... + m/m) 约为 mlogm 还有一个比较明显的结论,如果一个纪念品区间长度大于d,那么如果列车的停车间隔小于等于d,则这个纪念品一定能被买到 然后把区 ...

  2. [Leetcode] Reorder list 重排链表

    Given a singly linked list L: L 0→L 1→…→L n-1→L n,reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→… You ...

  3. 我用JAVA做了个简易图像相似度计算器

    简单说两句: 笔主利用这个七夕前后两天的寂寞时光,用JAVA磨了一个简单的图像相似度计算小程序,就在刚才终于纠结完毕,输出了1.0版本,小小的满足了一下可怜的虚荣心..→_→ 使用最简单最基础的感知哈 ...

  4. JQuery队列queue与原生模仿其实现

    jQuery中的queue和dequeue是一组很有用的方法,他们对于一系列需要按次序运行的函数特别有用.特别animate动画,ajax,以及timeout等需要一定时间的函数. queue() 方 ...

  5. JavaScript的大括号的语义

    Javascript中大括号"{}"有四种语义作用: 语义1. 组织复合语句,这是最常见的: view source   print? 1 if( condition ) { 2 ...

  6. 如何配置开源中国Maven库以加快依赖包下载速度

    有时有某些地方由于网络问题,访问maven主仓库比较慢,甚至有可能无法下载某些jar包,此时可以把开源中国Maven库配置到settings.xml文件中,加快依赖包的下载速度. 具体如何配置? 在m ...

  7. Codeforces Round #526 (Div. 2) D. The Fair Nut and the Best Path

    D. The Fair Nut and the Best Path 题目链接:https://codeforces.com/contest/1084/problem/D 题意: 给出一棵树,走不重复的 ...

  8. webstorm中把style的内容隐藏,如何把style的内容展开?

    我们经常看到在webstorm中style的内容以...表示如下图所示,只有把光标移到上面时才会看到内容: 如何把上述的style的内容展开呢? 请按一下步骤操作: 第一步:File------> ...

  9. bzoj 3771 Triple FFT 生成函数+容斥

    Triple Time Limit: 20 Sec  Memory Limit: 64 MBSubmit: 847  Solved: 482[Submit][Status][Discuss] Desc ...

  10. 编程技巧 - malloc()与free()

    1.要节省ram资源,可以使用malloc()动态申请内存,使用完再用free()释放掉,free()释放的是指针指向的内存空间,而不是指针. 2.如果某个大数组要在两个函数中使用,可以先定义一个全局 ...