๐Ÿ“˜ Day 15 โ€“ Teacher's Day Challenge | Boy or Girl

TanishiTanishi
2 min read

๐Ÿ—“๏ธ Date: August 08, 2025
๐Ÿงฉ Platform: Codeforces
๐Ÿ”ข Problems Solved Today: 1
๐ŸŽฏ Focus Topic: String Manipulation, Sets


๐Ÿ”— Table of Contents


๐Ÿงฉ Problem 1 โ€“ Boy or Girl

๐Ÿ“š Difficulty: Easy-Medium
๐Ÿง  Concepts: String Manipulation, Unique Characters


๐Ÿ“„ Problem Statement (Summary):
Given a username string consisting of lowercase English letters, determine the "gender" based on the count of distinct characters:

  • If the count is odd โ†’ Male โ†’ print "IGNORE HIM!"

  • If the count is even โ†’ Female โ†’ print "CHAT WITH HER!"


๐Ÿ”ข Input Format:
A single string containing only lowercase English letters (length โ‰ค 100).

๐Ÿงพ Output Format:
One of the following strings:

  • "CHAT WITH HER!" (female)

  • "IGNORE HIM!" (male)

๐Ÿ” Example 1:
Input:
wjmzbmr
Output:
CHAT WITH HER!

๐Ÿ” Example 2:
Input:
xiaodao
Output:
IGNORE HIM!

๐Ÿ” Example 3:
Input:
sevenkplus
Output:
CHAT WITH HER!


๐Ÿ’ก Approach:

  • Sort the string to group identical letters.

  • Remove duplicates to find the count of distinct characters.

  • Check if count is odd or even.

  • Output result accordingly.


๐Ÿงช Code (C++):

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    string str;
    cin >> str;
    int i = 0, j;
    sort(str.begin(), str.end());
    for (j = 1; j < str.length(); j++)
    {
        if (str[i] == str[j])
        {
            str.erase(j, 1);
            j--;
            i--;
        }
        i++;
    }
    if (str.length() & 1)
        cout << "IGNORE HIM!";
    else
        cout << "CHAT WITH HER!";
    return 0;
}

๐Ÿ“ธ Submission Screenshot:


โœ… Key Takeaways:

  • Sorting helps in grouping duplicates for easy removal.

  • Distinct character counting is a common string problem.

  • Simple logic with % 2 can determine parity-based decisions.


๐Ÿ“ˆ Daily Summary

MetricValue
Problems Solved1
Topics CoveredString Manipulation, Unique Characters
Tools UsedC++
Next FocusContinue String & Set-based Problems
Day15 / 43

๐Ÿท๏ธ Tags:
#codeforces #strings #cpp #beginner #dsa #43DaysChallenge

0
Subscribe to my newsletter

Read articles from Tanishi directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Tanishi
Tanishi