0w1

Yuki 341 沈黙の期間 ( UTF-8 )

http://yukicoder.me/problems/no/341
UTF-8 文字の比較問題なんですが C++ ではかなり面倒なようです。
なぜか RE するコードも載せたので、また時間あったらちゃんと見てみます。

#include <bits/stdc++.h>
using namespace std;

signed main(){
  wstring_convert< codecvt_utf8_utf16< char16_t >, char16_t > converter;
  string s; cin >> s;
  u16string us = converter.from_bytes( s );
  int ans = 0, cnt = 0;
  for( auto ch : us ){
    if( ch == u'…' )
      ans = max( ans, ++cnt );
    else
      cnt = 0;
  }
  cout << ans << endl;
  return 0;
}

RE:

#include <bits/stdc++.h>
using namespace std;

bool silent( string s ){
  wstring_convert< codecvt_utf8_utf16< char16_t >, char16_t > converter;
  u16string t = converter.from_bytes( s );
  for( auto &ch : t )
    if( ch == u'…' )
      return false;
  return true;
}

signed main(){
  string s; cin >> s;
  int ans = 0;
  for( int i = 0; i < s.size(); ++i )
    for( int j = i; j < s.size(); ++j )
      if( silent( s.substr( i, j - i + 1 ) ) )
        ans = max( ans, j - i + 1 );
  cout << ans << endl;
  return 0;
}