-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathProgram.cs
More file actions
32 lines (25 loc) · 734 Bytes
/
Program.cs
File metadata and controls
32 lines (25 loc) · 734 Bytes
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
using System;
namespace Counting_Valleys {
class Program {
public static int CountingValleys(int n, string s) {
int level = 0;
int valleys = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'U') {
if (++level == 0) {
valleys++;
}
} else {
level--;
}
}
return valleys;
}
static void Main(string[] args) {
int n = Convert.ToInt32(Console.ReadLine());
string s = Console.ReadLine();
int result = CountingValleys(n, s);
Console.WriteLine(result);
}
}
}