2017-9-3 校内模拟T1卡片card

题意:有三种字母,可以用两个不同的换一个第三种字母,两个相同的换一个同种字母(即消去一个),问最后剩下的字母。

第一题显然是if题,总体来说只有三种情况:

      1.有三种不同的>>输出“BGR”

      2.有两种不同的:{

    (1)两种都有超过一个>>情况1;

    (2)一种只有一个>>输出这种和未出现的字母

    (3)两种都只有一个>>输出未出现的字母
  }

   3.只有一种字母>>输出这个字母

代码(极丑):

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 using namespace std;
 5 int n;int o[4];int ans=6;
 6 void putout(int x){
 7     if(x==1) cout<<'B';
 8     if(x==2) cout<<'G';
 9     if(x==3) cout<<'R';
10 }
11 bool cmp(char a,char b){
12     return a<b;
13 }
14 int main(){
15     freopen("card.in","r",stdin);
16     freopen("card.out","w",stdout);
17     scanf("%d",&n);
18     char ll;int v=0;
19     getchar();
20     for(int i=0;i<n;i++){
21         ll=getchar();
22         if(ll=='B') o[1]++;
23         if(ll=='G') o[2]++;
24         if(ll=='R') o[3]++;
25     }
26     getchar();
27     if(o[1]&&o[2]&&o[3]){
28         printf("BGR
");
29         return 0;
30     }
31     for(int i=1;i<=3;i++){
32         if(!o[i]&&v!=0){
33             ans-=v+i;break;
34         }
35         else if(!o[i]) v=i;
36     }
37     if(ans!=6){
38         putout(ans);
39         return 0;
40     }
41     int a,b;
42     for(int i=1;i<=3;i++)
43         if(i!=v){
44             a=i,b=6-i-v;
45             break;
46         }
47     if(a>b) swap(a,b);
48     if((o[a]==1||o[b]==1)&&(o[a]!=1||o[b]!=1)){
49         int y=(o[a]==1?a:b);
50         if(y>6-a-b){
51             putout(6-a-b);
52             putout(y);
53         }
54         else{
55             putout(y);
56             putout(6-a-b);
57         }
58         cout<<endl;
59         return 0;
60     }
61     if(o[a]>1&&o[b]>1)
62         printf("BGR
");
63     else
64         putout(6-a-b);
65     return 0;
66 }

_________________________________

时间不早了,其它过两天再贴~

原文地址:https://www.cnblogs.com/JiuPleber/p/7470723.html