結果

問題 No.380 悪の台本
ユーザー どらえマン
提出日時 2016-06-18 00:27:59
言語 C++11
(gcc 4.8.5)
結果
AC  
実行時間 172 ms
コード長 3,461 Byte
コンパイル時間 573 ms
使用メモリ 1,660 KB
最終ジャッジ日時 2019-10-08 13:33:40

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
challenge01.txt AC 4 ms
1,524 KB
hand AC 3 ms
1,524 KB
sample1 AC 3 ms
1,520 KB
sample2 AC 4 ms
1,520 KB
test1 AC 11 ms
1,532 KB
test2 AC 24 ms
1,520 KB
test3 AC 23 ms
1,520 KB
test4 AC 172 ms
1,516 KB
test5 AC 7 ms
1,660 KB
test6 AC 12 ms
1,524 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