結果

問題 No.345 最小チワワ問題
ユーザー mosmos_21
提出日時 2016-10-12 22:14:51
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 526 bytes
コンパイル時間 237 ms
コンパイル使用メモリ 20,736 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-25 11:54:08
合計ジャッジ時間 948 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:24:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |   scanf("%s", in);
      |   ^~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
char in[101];
int count(int i){
  int p = 1, a = 1;
  while(in[i] != '\0'){
    switch(p){
    case 1:
      a++;
      if(in[i] == 'w') p = 2;
      break;
    case 2:
      a++;
      if(in[i] == 'w'){
        return a;
      }
    }
    i++;
  }
  return 101;
}

int main(){
  int ans = 101, i = 0, c;
  scanf("%s", in);

  while(in[i] != '\0'){
    if(in[i] == 'c'){
      c = count(i + 1);
      if(c < ans) ans = c;
    }
    i++;
  }  
  if(ans == 101) ans = -1;
  printf("%d\n", ans);
  return 0;
}
0