概述
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.
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
wjmzbmr
CHAT WITH HER!
xiaodao
IGNORE HIM!
sevenkplus
CHAT WITH HER!
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!".
解题思路:本题大意为,若字符串中所出现的字符类型数量为奇数则为male,否则为female。解题过程中使用了Set集合不重复特性,所以仅需set.size()就知道该字符串字符类型的数目。
提醒: "wjmzbmr" 中只有6个字符,虽然length=7,但是m重复了一次,因此还是仅有六个,所以输出"CHAT WITH HER!"
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
char[] ch = str.toCharArray();
Set
set = new HashSet
();
for(int i = 0;i < ch.length;i++){
set.add(ch[i]);
}
if(set.size() % 2 == 0){
System.out.println("CHAT WITH HER!");
}else{
System.out.println("IGNORE HIM!");
}
scanner.close();
}
}
最后
以上就是无聊航空为你收集整理的Codeforces刷题之路——236A Boy or Girl的全部内容,希望文章能够帮你解决Codeforces刷题之路——236A Boy or Girl所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复