Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Counting Valleys
- #include <iostream>
- using namespace std;
- int main()
- {
- long long int n, lvl=0, dwn=0, val=0;
- char z;
- cin >> n;
- for(int i=0;i<n;i++)
- {
- cin >> z;
- if(z=='U'){lvl+=1;}
- else if(z=='D'){lvl-=1;}
- if(lvl<0 && dwn!=1){dwn=1;}
- if(dwn==1 && lvl>=0){val+=1;dwn=0;}
- }
- cout<<val;
- return 0;
- }
Add Comment
Please, Sign In to add comment