ichirin2501's diary

いっちりーん。

問題 B - (iwi)

http://atcoder.jp/problem/detail/26
96分(13分)で正解


単純な文字列処理

int main(){
  string str;
  while(cin>>str){
    int n = str.length();
    int ret = 0;
    rep(i,n/2){
      if( str[i]=='(' ){
	if( str[n-i-1]!=')' ) ret++;
      }else if( str[i]==')' ){
	if( str[n-i-1]!='(' ) ret++;
      }else if( str[i]!=str[n-i-1] ){
	ret++;
      }
    }
    if( n%2==1 && !(str[n/2]=='i' || str[n/2]=='w') ){
      ret++;
    }
    cout << ret << endl;
  }
  return 0;
}