Jishan's Log 12: Codeforces 236A solution

Codeforces 236A: Boy or Girl

The Problem:

A person tries to figure out how to distinct a boy and girl in an online chat platform. A boys account will have odd number of distinct characters.

Here, distinct characters mean the total number of the type of characters. 
Ex:
string: AB
distinct chars: 2 (there are two types: A and B)
string: ABBAACCD
distinct chars: 4 (there are four types: A, B, C and D)

The Solution:

The Algorithm:

1) take a string
2) take a set of chars and insert each char in string into set.
3) count the number of chars in the set
4) if odd print "IGNORE HIM", else "CHAT WITH HER!".
NOTE: We used set here because it does not take ANY DUPLICATE VALUES. If a value is already in the set, it will ignore it.

The Code:

#include<bits/stdc++.h>

#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int main()
{
    string strcin >> str;
    set<char> words;
    for(auto ch : str){
        words.insert(ch);
    }

    auto counter = 0;
    for(auto i = words.begin(); i != words.end(); i++){
        counter++;
    }

    if(counter % 2 == 0)
    {
        printf("CHAT WITH HER!\n");
    }
    else
    {
        printf("IGNORE HIM!\n");
    }
}

Comments

Popular posts from this blog

Jishan's Log 14: Codeforces 69A solution

Jishan's Log 13: Codeforces 96A solution