Created
August 24, 2021 01:19
-
-
Save esthicodes/6ec853f86215f813d430509b515c019c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <math.h> | |
#include <stdlib.h> | |
int main() { | |
int n; | |
scanf("%i", &n); | |
char str[n]; | |
scanf("%s", str); | |
int level = 0, result = 0, valley = 0; | |
for (int i = 0; i < n; i++) { | |
if(str[i] == 'U') { | |
level++; | |
if(level == 0 && valley) { | |
valley = 0; | |
result++; | |
} | |
} | |
else if(str[i] == 'D') { | |
if(level == 0) | |
valley = 1; | |
level--; | |
} | |
} | |
printf("%i", result); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment