[CF从零单排#10]236A - Boy or Girl

题目来源:http://codeforces.com/problemset/problem/236/A

Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.
This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.

Input
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.

Output
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).

Examples
input
wjmzbmr
output
CHAT WITH HER!

input
xiaodao
output
IGNORE HIM!

input
sevenkplus
output
CHAT WITH HER!

Note
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".

题目大意:

通过一个人的id号码来判定是男孩还是女孩。id都由小写字母构成,且长度不超过50。如果id中不同的字母个数是偶数,说明是女孩,输出"CHAT WITH HER!",否则是男孩,输出"IGNORE HIM!"。

题目分析:

类似于桶排的方法,用一个数组a[k]来表示k这个字母是否存在。扫描一遍整个id,那么就可以统计出共有多少个不同的字母,再判定奇偶就可以了。

参考代码:

#include <bits/stdc++.h>
using namespace std;
int main(){
	char s[110];
	int a[30];
	cin >> s;
	int len = strlen(s);
	memset(a, 0, sizeof(a));
	for(int i=0; i<len; i++){
		a[s[i]-'a'] ++;
	}
	int ans = 0;
	for(int i=0; i<26; i++)
		if(a[i]>0)
			ans++;
	if(ans%2==0)
		cout << "CHAT WITH HER!";
	else
		cout << "IGNORE HIM!"; 
	return 0;
} 
posted @ 2020-07-24 17:05  gdgzliu  阅读(200)  评论(0)    收藏  举报