頭良くなりたい人

文系大学生shadeのブログです。競技プログラミングや人文学の話題,受験ネタなど。

ABC052 B - Increment Decrement

問題はこちら atcoder.jp

方針

特になし。

コード

#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    string s;
    cin>>n>>s;
 
    int x=0;
    int x_max=0;
 
    for(int i=0; i<n; i++){
        if(s.at(i)=='I'){
            x++;
        }else{
            x--;
        }
        if(x>x_max){
            x_max=x;
        }
    }
 
    cout<<x_max<<endl;
}