結果

問題 No.150 "良問"(良問とは言っていない
ユーザー alpha_virginisalpha_virginis
提出日時 2015-06-14 15:46:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,154 bytes
コンパイル時間 1,342 ms
コンパイル使用メモリ 159,204 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 09:25:50
合計ジャッジ時間 2,002 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int main() {

  int N;
  int diff_g[128];
  int diff_p[128];
  int ans;
  std::string str;
  int count;

  std::cin >> N;
  for(int i = 0; i < N; ++i) {
    std::cin >> str;
    for(int j = 0; j < 128; ++j) {
      diff_g[j] = 10000;
      diff_p[j] = 10000;
    }

    for(int j = 0; j <= str.size()-4; ++j) {
      count = 0;
      if( str[j]   != 'g' ) count += 1;
      if( str[j+1] != 'o' ) count += 1;
      if( str[j+2] != 'o' ) count += 1;
      if( str[j+3] != 'd' ) count += 1;
      diff_g[j] = count;
    }
    for(int j = 0; j <= str.size()-7; ++j) {
      count = 0;
      if( str[j]   != 'p' ) count += 1;
      if( str[j+1] != 'r' ) count += 1;
      if( str[j+2] != 'o' ) count += 1;
      if( str[j+3] != 'b' ) count += 1;
      if( str[j+4] != 'l' ) count += 1;
      if( str[j+5] != 'e' ) count += 1;
      if( str[j+6] != 'm' ) count += 1;
      diff_p[j] = count;
    }

    ans = 10000;
    for(int j = 0; j <= str.size()-4-7; ++j) {
      for(int k = j+4; k <= str.size()-7; ++k) {
	ans = std::min(ans, diff_g[j]+diff_p[k]);
      }
    }
    
    std::cout << ans << std::endl;
  }    

  return 0;
}
	
0