#include #include #include #include int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n; scanf("%d",&n); char *height = malloc(sizeof(char) * n); for(int height_i = 0; height_i < n+1; height_i++){ scanf("%c",&height[height_i]); } //printf("%s",height); int ch = 0; // + is above sea level, - is below int count = 0; int dfs = 0; // DDUU DDUD UUUD // ch = -1, -2, -1, -2, -1, // dfs = 1, 0 //printf("n = %d\n",n); //printf("array = '%s' \n",height); for( int i = 1; i < n+1; i++ ){ //printf("%c ", height[i] ); if( height[i] == 'U' ){ //printf("uphill\n"); if( ch == -1 ){ if( dfs == 1 ){ count ++; } dfs = 0; } ch++; } else{ //printf("downhill\n"); if( ch == 0 ){ dfs = 1; } ch--; } //printf("i = %d, ch = %d , dfs = %d, count = %d\n",i,ch,dfs,count); } printf("%d",count); return 0; }