結果

問題 No.346 チワワ数え上げ問題
ユーザー kapokapo
提出日時 2016-05-03 20:08:10
言語 C90
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 544 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 22,272 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-15 11:03:02
合計ジャッジ時間 4,264 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,784 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 50 ms
5,376 KB
testcase_11 AC 18 ms
5,376 KB
testcase_12 AC 31 ms
5,376 KB
testcase_13 AC 15 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 26 ms
5,376 KB
testcase_16 AC 35 ms
5,376 KB
testcase_17 AC 49 ms
5,376 KB
testcase_18 AC 47 ms
5,376 KB
testcase_19 AC 38 ms
5,376 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:14:9: warning: implicit declaration of function ‘scanf’ [-Wimplicit-function-declaration]
   14 |         scanf("%s", &a);
      |         ^~~~~
main.c:2:1: note: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
    1 | #include <string.h>
  +++ |+#include <stdio.h>
    2 | 
main.c:14:9: warning: incompatible implicit declaration of built-in function ‘scanf’ [-Wbuiltin-declaration-mismatch]
   14 |         scanf("%s", &a);
      |         ^~~~~
main.c:14:9: note: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
main.c:14:17: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[100001]’ [-Wformat=]
   14 |         scanf("%s", &a);
      |                ~^   ~~
      |                 |   |
      |                 |   char (*)[100001]
      |                 char *
main.c:16:26: warning: comparison between pointer and integer
   16 |         for( i = 0; a[i] != NULL; i++) {
      |                          ^~
main.c:24:26: warning: comparison between pointer and integer
   24 |         for( i = 0; s[i] != NULL; i++) {
      |                          ^~
main.c:27:44: warning: comparison between pointer and integer
   27 |                         for( j = i+1; s[j] != NULL; j++) {
      |                                            ^~
main.c:33:9: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
   33 |         printf("%.lf\n", sum);
      |         ^~~~~~
main.c:33:9: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
main.c:33:9: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
main.c:33:9: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’

ソースコード

diff #

#include <string.h>

double combi(int c)
{
	if( c < 2 ) return 0;
	return (double)c*((double)c-1)/2;
}

int main(void)
{
	int i, j;
	double sum = 0;
	char s[100001] = {'\0'}, a[100001];
	scanf("%s", &a);

	for( i = 0; a[i] != NULL; i++) {
		if( a[i] == 'w' ) {
			strcat(s, "w");
		} else if ( a[i] == 'c' ) {
			strcat(s, "c");
		}
	}

	for( i = 0; s[i] != NULL; i++) {
		if( s[i] == 'c' ) {
			int wc = 0;
			for( j = i+1; s[j] != NULL; j++) {
				if( s[j] == 'w' ) wc++;
			}
			sum += combi(wc);
		}
	}
	printf("%.lf\n", sum);

	return 0;
}
0