結果

問題 No.380 悪の台本
ユーザー どららどらら
提出日時 2016-06-18 00:27:59
言語 C++11
(gcc 4.8.5)
結果
AC  
実行時間 164 ms / 1,000 ms
コード長 3,461 Byte
コンパイル時間 506 ms
使用メモリ 8,944 KB
最終ジャッジ日時 2020-07-13 06:20:14

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
6,896 KB
testcase_01 AC 3 ms
8,940 KB
testcase_02 AC 2 ms
8,944 KB
testcase_03 AC 2 ms
8,940 KB
testcase_04 AC 9 ms
8,940 KB
testcase_05 AC 19 ms
6,896 KB
testcase_06 AC 19 ms
6,892 KB
testcase_07 AC 164 ms
8,936 KB
testcase_08 AC 5 ms
8,900 KB
testcase_09 AC 10 ms
8,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

bool prefix_check(const string& prefix, const string& str){
  if(prefix.size() > str.size()) return false;
  rep(i,prefix.size()){
    if(str[i]!=prefix[i]) return false;
  }
  return true;
}

bool is_symbol(char c){
  if((' '<=c && c<='/') ||
     (':'<=c && c<='@') ||
     ('['<=c && c<='`') ||
     ('{'<=c && c<='~')){
    return true;
  }
  return false;
}

bool suffix_check(int st, const string& suffix, const string& str){
  if(str.size()-st < suffix.size()) return false;
  if(str.size()-suffix.size()>=st){
    bool flg = true;
    rep(i,suffix.size()){
      int offset = str.size()-suffix.size();
      if(suffix[i] != str[offset+i]) flg = false;
    }
    if(flg) return true;
  }
  if(str.size()-suffix.size()-1>=st){
    bool flg = true;
    rep(i,suffix.size()){
      int offset = str.size()-suffix.size()-1;
      if(suffix[i] != str[offset+i]) flg = false;
    }
    if(!is_symbol(str[str.size()-1])) flg = false;
    if(flg) return true;
  }
  if(str.size()-suffix.size()-2>=st){
    bool flg = true;
    rep(i,suffix.size()){
      int offset = str.size()-suffix.size()-2;
      if(suffix[i] != str[offset+i]) flg = false;
    }
    if(!is_symbol(str[str.size()-1])) flg = false;
    if(!is_symbol(str[str.size()-2])) flg = false;
    if(flg) return true;
  }
  if(str.size()-suffix.size()-3>=st){
    bool flg = true;
    rep(i,suffix.size()){
      int offset = str.size()-suffix.size()-3;
      if(suffix[i] != str[offset+i]) flg = false;
    }
    if(!is_symbol(str[str.size()-1])) flg = false;
    if(!is_symbol(str[str.size()-2])) flg = false;
    if(!is_symbol(str[str.size()-3])) flg = false;
    if(flg) return true;
  }
  return false;
}

bool include_char(int st, const string& str){
  REP(i,st,str.size()){
    if(!is_symbol(str[i])) return true;
  }
  return false;
}

int main(){
  string str;
  while(getline(cin, str)){
    bool flg = false;
    if(prefix_check("digi ", str)){
      string foo = str;
      std::transform(foo.begin(), foo.end(), foo.begin(), ::tolower);
      if(suffix_check(5, "nyo", foo)) flg = true;
    }
    else if(prefix_check("petit ", str)){
      string foo = str;
      std::transform(foo.begin(), foo.end(), foo.begin(), ::tolower);
      if(suffix_check(6, "nyu", foo)) flg = true;
    }
    else if(prefix_check("rabi ", str)){
      string foo = str;
      std::transform(foo.begin(), foo.end(), foo.begin(), ::tolower);
      if(include_char(5, foo)) flg = true;
    }
    else if(prefix_check("gema ", str)){
      string foo = str;
      std::transform(foo.begin(), foo.end(), foo.begin(), ::tolower);
      if(suffix_check(5, "gema", foo)) flg = true;
    }
    else if(prefix_check("piyo ", str)){
      string foo = str;
      std::transform(foo.begin(), foo.end(), foo.begin(), ::tolower);
      if(suffix_check(5, "pyo", foo)) flg = true;
    }

    if(flg){
      cout << "CORRECT (maybe)" << endl;
    }else{
      cout << "WRONG!" << endl;
    }
  }
  
  return 0;
}
0