码迷,mamicode.com
首页 > 其他好文 > 详细

17-09-03模拟赛

时间:2017-09-04 14:53:22      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:tchar   name   print   ret   can   names   get   log   for   

T1:考虑根据各颜色卡牌的数量进行分类讨论。

Code:

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 inline int in(){
 6     int x=0;bool f=0; char c;
 7     for (;(c=getchar())<0||c>9;f=c==-);
 8     for (x=c-0;(c=getchar())>=0&&c<=9;x=(x<<3)+(x<<1)+c-0);
 9     return f?-x:x;
10 }
11 const char ch[3]={B,G,R};
12 int sum[3],a[4],b[4],c[4],cnt[3],n;
13 char s[205];
14 int main()
15 {
16     n=in();if (!n) return 0;scanf("%s",&s);
17     for (int i=0;i<n;++i) {
18         switch (s[i]){
19             case B:++sum[0];break;
20             case G:++sum[1];break;
21             case R:++sum[2];break;
22         }
23     }
24     for (int i=0;i<3;++i){
25         if (!sum[i]) a[++cnt[0]]=i;
26         else if (sum[i]==1) b[++cnt[1]]=i;
27         else c[++cnt[2]]=i;
28     }
29     if (!cnt[0]) {printf("BGR");return 0;}
30     if (cnt[0]==2) {printf("%c",cnt[1]?ch[b[1]]:ch[c[1]]);return 0;}
31     if (!cnt[1]) {printf("BGR");return 0;}
32     if (cnt[1]==2) {printf("%c",ch[a[1]]);return 0;}
33     if (cnt[1]==1) {ch[a[1]]<ch[b[1]]?printf("%c%c",ch[a[1]],ch[b[1]]):printf("%c%c",ch[b[1]],ch[a[1]]);return 0;}
34     return 0;
35 }

 

17-09-03模拟赛

标签:tchar   name   print   ret   can   names   get   log   for   

原文地址:http://www.cnblogs.com/codingutopia/p/test170903.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!