Getting Started 7 string exercises boy or girl explanations

Written for: http://codeforces.com/problemset/problem/236/A

Title Description

Nowadays, a lot of pretty girls boys use the photo as an avatar in the forum. So to determine a user's gender becomes a difficult task.
Last year, our Cong Cong into a forum, and and a (he considers) the girls talk.
They talk very speculative, full, they began a courtship.
However, just yesterday, Cong Cong and her "girlfriend" touched the surface in the real world, and found that "she" is actually a very strong man!
Our Cong Cong feel more heart-breaking, the feeling never love again.
So we propose a set of Cong Cong determine the sex of the user name algorithm.
This algorithm is implemented so:
if the number of a user's user name in different words is an odd number, then he was a boy; otherwise (even number), she is a girl.
Give you a user name, please use this algorithm Cong Cong to determine whether he was a boy or a girl.

Input Format

Comprising input contains only a non-empty string of lowercase letters, for indicating the user name. Length of the string will not exceed 100.

Output Format

According to Cong Cong's algorithm, if the user is a girl come to this, the output "CHAT WITH HER!"; Otherwise (boys), the output "IGNORE HIM!".

Sample input 1

wjmzbmr

Sample output 1

CHAT WITH HER!

Sample input 2

xiaodao

Sample output 2

IGNORE HIM!

Sample input 3

sevenkplus

Sample output 3

CHAT WITH HER!

Topic analysis

This question we actually open a long length of array 26, for recording the 'a' to 'z' which no word has 26 occurred.
Then a word that appears statistics about the number is odd or even number on it.
Code is implemented as follows:

#include <bits/stdc++.h>
using namespace std;

bool vis[26];
string s;
int n, cnt;

int main() {
    cin >> s;
    n = s.length();
    for (int i = 0; i < n; i ++) {
        vis[ s[i] - 'a' ] = true;
    }
    for (int i = 0; i < 26; i ++) if (vis[i]) cnt ++;
    puts(cnt % 2 ? "IGNORE HIM!" : "CHAT WITH HER!");
    return 0;
}

Guess you like

Origin www.cnblogs.com/zifeiynoip/p/11450584.html