#include #include #include #include #include using namespace std; #define MOUNTAINS 1 #define VALLEY -1 #define NO_CHANGE 0 int checkMountainOrValley(int height, char previous) { if(height == 0 && previous == 'U') return VALLEY; else if(height == 0 && previous == 'D') return MOUNTAINS; else return NO_CHANGE; } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int height = 0; int n = 0; cin >> n; string str; cin >> str; int cnt_mount = 0; int cnt_valley = 0; int status = 0; for (int i = 0; i < str.size(); i++) { if(str[i] == 'U') { height++; } else if(str[i] == 'D') { height--; } status = checkMountainOrValley(height, str[i]); if(status == MOUNTAINS) cnt_mount++; else if(status == VALLEY) cnt_valley++; else ; } cout << cnt_valley; return 0; }