1252: 缺失的彩虹

题目描述

众所周知,彩虹有7种颜色,我们给定七个 字母和颜色 的映射,如下所示:
'A' -> "red"
'B' -> "orange"
'C' -> "yellow"
'D' -> "green"
'E' -> "cyan"
'F' -> "blue"
'G' -> "purple"
但是在某一天,彩虹的颜色少了几种,你能告诉PIPI哪些彩虹的颜色没有出现过吗?

输入

输入包含多组测试用例。
对于每组测试用例,输入n个合法的颜色字符串(0<=n<=100),输出有多少种颜色没有出现过,并分别输出对应的字母。

输出

对于每一组测试样例,输出一个数字,代表缺失的颜色种数,然后按照升序输出缺失颜色对应的字母。

样例输入

3
red
orange
cyan

样例输出

4 
C
D
F
G

来源/分类

2020中南大学研究生招生夏令营机试题 

解题思路

用一个数组标记哪些颜色出现过哪些颜色没有出现过

AC Code

#include<iostream>
#include<cmath>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
typedef long long ll;
const double PI=acos(-1);
const double EPS=1e-6;
const int MAXN=1000+10;
using namespace std;
bool is[7];
int main(){

    //freopen("C:\\Users\\Ambition\\Desktop\\in.txt","r",stdin);
	int n;
	while(scanf("%d",&n)!=EOF){
		memset(is,0,sizeof(is));
		for(int i=0; i<n; ++i){
			scanf("%s",color);
			switch(color[0]){
				case 'r': is[0]=1; 	break;
				case 'o': is[1]=1;	break;
				case 'y': is[2]=1;	break;
				case 'g': is[3]=1;	break;
				case 'c': is[4]=1;	break;
				case 'b': is[5]=1;	break;
				case 'p': is[6]=1;	break;
				default: break;
			}
		}
		//计算有多少种颜色没出现过 
		int count=0;
		for(int i=0; i<7; ++i){
			if(!is[i]) count++;
		}
		printf("%d\n",count);
		//输出没出现的颜色 
		for(int i=0; i<7; ++i){
			if(!is[i]){
				char ch='A'+i;
				printf("%c\n",ch);
			}
		}
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值