結果
問題 |
No.346 チワワ数え上げ問題
|
ユーザー |
![]() |
提出日時 | 2016-05-03 19:47:52 |
言語 | C90 (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 555 bytes |
コンパイル時間 | 216 ms |
コンパイル使用メモリ | 22,016 KB |
実行使用メモリ | 13,632 KB |
最終ジャッジ日時 | 2024-10-05 05:22:01 |
合計ジャッジ時間 | 4,485 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | WA * 20 TLE * 1 -- * 2 |
コンパイルメッセージ
main.c: In function ‘main’: 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:26:26: warning: comparison between pointer and integer 26 | for( i = 0; s[i] != NULL; i++) { | ^~ main.c:29:44: warning: comparison between pointer and integer 29 | for( j = i+1; s[j] != NULL; j++) { | ^~ main.c:14:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | scanf("%s", &a); | ^~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <string.h> int combi(int c) { if( c < 2 ) return 0; return c*(c-1)/2; } int main(void) { int i, j, 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"); } } printf("%s\n", s); 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("%d\n", sum); return 0; }