I have not been blogging for a while, because I got a little deeper into reading the SQL books, which are waiting for review and thus I have decided to blog about something today. Initially, the idea was to write about SELECT INTO or something like it, but I have considered that the web is full with better samples of SQL code so far. Thus, I have taken a look at the last CodeForces competition and I somehow noticed, that the first problem is unbelievably easy somehow. I have decided to solve it and within some 2 minutes I had a running answer. Thus, I have decided to dedicate an article about it 🙂
My solution was just to read the first string of the input, then to put a for loop, reading the next and to put everything in one string. Then it is easy to say whether you have cyan, magenta or yellow at all, just by comparing with -1. Honestly, I did not believe that it is that easy, but it was. Thus, my code worked:
Here comes the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
using System; class check01 { static void Main() { string[] input = Console.ReadLine().Split(); int i_row = int.Parse(input[0]); string str_result = ""; for (int i = 0; i < i_row; i++) { str_result += Console.ReadLine(); } if ((str_result.IndexOf('C') != -1) || (str_result.IndexOf('M') !=-1) || (str_result.IndexOf('Y') != -1)) { Console.WriteLine("#Color"); } else { Console.WriteLine("#Black&White"); } } } |
The funny part is that in C# I do not even need to care for the number of columns. In this tiny example C# produces better results than C++ and C 🙂
Enjoy it!