結果

問題 No.380 悪の台本
ユーザー 0w10w1
提出日時 2016-11-29 16:26:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 1,000 ms
コード長 2,621 bytes
コンパイル時間 1,785 ms
コンパイル使用メモリ 173,680 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-06 20:13:40
合計ジャッジ時間 2,523 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 9 ms
4,380 KB
testcase_05 AC 23 ms
4,384 KB
testcase_06 AC 22 ms
4,376 KB
testcase_07 AC 135 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 10 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const string msg[] = { "WRONG!", "CORRECT (maybe)" };
const string pn[] = { "digi", "petit", "rabi", "gema", "piyo" };

int sym( const string &s ){
  for( int i = 0; i < s.size(); ++i ){
    if( 'a' <= s[ i ] and s[ i ] <= 'z' )
      return 0; 
    if( 'A' <= s[ i ] and s[ i ] <= 'Z' )
      return 0;
    if( '0' <= s[ i ] and s[ i ] <= '9' )
      return 0;
  }
  return 1;
}

signed main(){
  string buff;
  while( getline( cin, buff ) ){
    if( buff.empty() or buff[ 0 ] == ' ' ){
      cout << msg[ 0 ] << endl;
      continue;
    }
    stringstream ss( buff );
    string s;
    int p = 0;
    string name;
    int ng = 0;
    while( ss >> s ){
      if( p == 0 ){
        name = s;
        int ok = 0;
        for( int i = 0; i < 5; ++i )
          ok |= name == pn[ i ];
        ng |= not ok;
        break;
      }
      ++p;
    }
    for( int i = 0; i < buff.size(); ++i )
      if( 'A' <= buff[ i ] and buff[ i ] <= 'Z' )
        buff[ i ] = buff[ i ] - 'A' + 'a';
    if( name.empty() ){
      cout << msg[ 0 ] << endl;
      continue;
    }
    string z = buff.substr( name.size() );
    if( name == pn[ 0 ] ){
      // string z = buff;
      int ok = 0;
      for( int i = 0; i + 3 <= z.size(); ++i )
        if( z.substr( i, 3 ) == "nyo" and sym( z.substr( i + 3 ) ) )
          ok |= ( int ) z.size() - ( i + 3 ) <= 3;
      ng |= not ok; 
    } else if( name == pn[ 1 ] ){
      // string z;
      // for( int i = 0; i < dict.size(); ++i )
        // z += dict[ i ];
      int ok = 0;
      for( int i = 0; i + 3 <= z.size(); ++i )
        if( z.substr( i, 3 ) == "nyu" and sym( z.substr( i + 3 ) ) )
          ok |= ( int ) z.size() - ( i + 3 ) <= 3;
      ng |= not ok;
    } else if( name == pn[ 2 ] ){
      // string z;
      // for( int i = 0; i < dict.size(); ++i )
      int ok = 0;
      for( int i = 0; i < z.size(); ++i )
        ok |= 'a' <= z[ i ] and z[ i ] <= 'z',
        ok |= 'A' <= z[ i ] and z[ i ] <= 'Z',
        ok |= '0' <= z[ i ] and z[ i ] <= '9';
      ng |= not ok;
    } else if( name == pn[ 3 ] ){
      int ok = 0;
      for( int i = 0; i + 4 <= z.size(); ++i )
        if( z.substr( i, 4 ) == "gema" and sym( z.substr( i + 4 ) ) )
          ok |= ( int ) z.size() - ( i + 4 ) <= 3;
      ng |= not ok;
    } else if( name == pn[ 4 ] ){
      int ok = 0;
      for( int i = 0; i + 3 <= z.size(); ++i )
        if( z.substr( i, 3 ) == "pyo" and sym( z.substr( i + 3 ) ) )
          ok |= ( int ) z.size() - ( i + 3 ) <= 3;
      ng |= not ok;
    }
    cout << msg[ not name.empty() and not ng ] << endl;
  }
  return 0;
}
0