题目描述
众所周知,彩虹有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
来源/分类
解题思路
用一个数组标记哪些颜色出现过哪些颜色没有出现过
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;
}