結果

問題 No.380 悪の台本
ユーザー tnakao0123tnakao0123
提出日時 2016-07-13 20:34:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,232 bytes
コンパイル時間 779 ms
コンパイル使用メモリ 90,296 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 14:42:22
合計ジャッジ時間 1,437 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 380.cc: No.380 悪の台本 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef vector<string> vs;

/* global variables */

/* subroutines */

string readword(string &s, int &pos) {
  while (pos < s.size() && s[pos] == ' ') pos++;
  string w;
  while (pos < s.size() && s[pos] != ' ') w += s[pos++];
  return w;
}

inline bool is_upper(char c) { return (c >= 'A' && c <= 'Z'); }
inline bool is_lower(char c) { return (c >= 'a' && c <= 'z'); }
inline bool is_digit(char c) { return (c >= '0' && c <= '9'); }

inline bool not_symbol(char c) {
  return is_upper(c) || is_lower(c) || is_digit(c);
}
inline bool is_symbol(char c) { return ! not_symbol(c); }

bool end_with(string &w, string key) {
  int wn = w.size(), kn = key.size();
  int l = wn;
  while (l > 0 && is_symbol(w[l - 1])) l--;
  if (wn - l > 3 || l < kn) return false;
  for (int i = 0; i < kn; i++) {
    char c = w[l - kn + i];
    if (is_upper(c)) c += 'a' - 'A';
    if (c != key[i]) return false;
  }
  return true;
}

/* main */

int main() {
  for (;;) {
    string s;
    getline(cin, s);
    if (cin.eof()) break;

    vs v;
    for (int pos = 0;;) {
      string w = readword(s, pos);
      if (w.empty()) break;
      v.push_back(w);
    }
    int n = v.size();
    //printf("%d\n", n);

    if (n <= 1) {
      puts("WRONG!");
      continue;
    }

    bool ok = false;
    string &name = v.front(), &lw = v.back();

    if (name == "digi")
      ok = end_with(lw, "nyo");
    else if (name == "petit")
      ok = end_with(lw, "nyu");
    else if (name == "gema")
      ok = end_with(lw, "gema");
    else if (name == "piyo")
      ok = end_with(lw, "pyo");
    else if (name == "rabi") {
      for (int i = 1; ! ok && i < n; i++)
	for (int j = 0; ! ok && j < v[i].size(); j++)
	  ok = not_symbol(v[i][j]);
    }

    cout << (ok ? "CORRECT (maybe)" : "WRONG!") << endl;
  }

  return 0;
}
0