Codeforces: 236A. Boy or Girl ?


The problem is from codeforces: http://www.codeforces.com/problemset/problem/236/A

236A Codeforces: 236A. Boy or Girl ? algorithms brute force c # codeforces implementation programming languages

This simple problem can be solved easily. I use C# to practice the use of Hashset. Bruteforce O(n) each character and count the identical characters.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// acm.steakovercooked.com
using System;
using System.Collections.Generic;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            HashSet<char> aa = new HashSet<char>();
            string s = Console.ReadLine();
            foreach (char ch in s)
            {
                if (!aa.Contains(ch))
                {
                    aa.Add(ch);
                }
            }
            Console.Write((aa.Count & 1) == 0 ? "CHAT WITH HER!" : "IGNORE HIM!");
        }
    }
}
// acm.steakovercooked.com
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            HashSet<char> aa = new HashSet<char>();
            string s = Console.ReadLine();
            foreach (char ch in s)
            {
                if (!aa.Contains(ch))
                {
                    aa.Add(ch);
                }
            }
            Console.Write((aa.Count & 1) == 0 ? "CHAT WITH HER!" : "IGNORE HIM!");
        }
    }
}

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
171 words
Last Post: Codeforces: 237A Free Cash
Next Post: Sign Area of Irregular Polygon

The Permanent URL is: Codeforces: 236A. Boy or Girl ?

Leave a Reply