-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathProgram.cs
More file actions
61 lines (51 loc) · 1.91 KB
/
Program.cs
File metadata and controls
61 lines (51 loc) · 1.91 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Collections.Generic;
namespace Happy_Ladybugs {
class Program {
public static string HappyLadybugs(int numberOfCells, string board) {
Dictionary<char, int> colorFrequency = new Dictionary<char, int>();
foreach (char letter in board) {
if (colorFrequency.ContainsKey(letter)) {
colorFrequency[letter]++;
} else {
colorFrequency[letter] = 1;
}
}
// Verify if each color has at least a frequency of 2
foreach (var frequency in colorFrequency) {
if (frequency.Value < 2 && frequency.Key != '_') {
return "NO";
}
}
// Verify if it contains an empty cell
if (colorFrequency.ContainsKey('_')) {
return "YES";
} else {
// If it has no empty cell, check if it is already in order
int count = 1;
for (int i = 1; i < board.Length; i++) {
if (board[i] == board[i - 1]) {
count++;
continue;
} else {
if (count < 2) {
return "NO";
} else {
count = 1;
}
}
}
return "YES";
}
}
static void Main(string[] args) {
int numberOfGames = Convert.ToInt32(Console.ReadLine().Trim());
for (int i = 0; i < numberOfGames; i++) {
int numberOfCells = Convert.ToInt32(Console.ReadLine().Trim());
string board = Console.ReadLine();
string result = HappyLadybugs(numberOfCells, board);
Console.WriteLine(result);
}
}
}
}