結果

問題 No.345 最小チワワ問題
コンテスト
ユーザー mosmos_21
提出日時 2016-10-12 22:19:02
言語 C90
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 435 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 146 ms
コンパイル使用メモリ 29,252 KB
最終ジャッジ日時 2026-02-23 22:32:32
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:17:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |   scanf("%s", in);
      |   ^~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <stdio.h>
char in[101];
int count(int i){
  int p = 1, a = 1;
  while(in[i] != '\0'){
    a++;
    if(in[i]=='w')
      if(p==1) p++;
      else 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