-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCountingValleys.cpp
More file actions
50 lines (35 loc) · 789 Bytes
/
CountingValleys.cpp
File metadata and controls
50 lines (35 loc) · 789 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// problem: "https://www.hackerrank.com/challenges/counting-valleys/problem"
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
long int n;
char ch[1000000];
cin>>n;
for(int i=0;i<n;i++)
cin>>ch[i];
int countU=0,countD=0,countV=0;
for(int j=0;j<n;j++)
{
if(ch[j]=='U')
countU++;
if(ch[j]=='D')
countD++;
//if(countD>countU)
//
if(countD==countU)
{
if(ch[j]=='U')
{
countV++;
}
countU=countD=0;
}
}
cout<<countV;
return 0;
}