結果
問題 |
No.289 数字を全て足そう
|
ユーザー |
![]() |
提出日時 | 2025-03-03 17:06:21 |
言語 | C (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 357 bytes |
コンパイル時間 | 494 ms |
コンパイル使用メモリ | 24,704 KB |
実行使用メモリ | 8,608 KB |
最終ジャッジ日時 | 2025-03-03 17:06:26 |
合計ジャッジ時間 | 4,721 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 3 |
other | WA * 1 RE * 20 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:16:27: warning: passing argument 1 of ‘snprintf’ makes pointer from integer without a cast [-Wint-conversion] 16 | snprintf(p[i], 1, "%d", tmp); | ~^~~ | | | char In file included from /usr/include/features.h:502, from /usr/include/x86_64-linux-gnu/bits/libc-header-start.h:33, from /usr/include/stdio.h:28, from main.c:1: /usr/include/x86_64-linux-gnu/bits/stdio2.h:51:1: note: expected ‘char * restrict’ but argument is of type ‘char’ 51 | __NTH (snprintf (char *__restrict __s, size_t __n, | ^~~~~ main.c:7:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 7 | scanf("%s",str); | ^~~~~~~~~~~~~~~ main.c:16:38: warning: ‘__builtin___snprintf_chk’ output truncated before the last format character [-Wformat-truncation=] 16 | snprintf(p[i], 1, "%d", tmp); | ^ In file included from /usr/include/stdio.h:980: In function ‘snprintf’, inlined from ‘main’ at main.c:16:10: /usr/include/x86_64-linux-gnu/bits/stdio2.h:54:10: note: ‘__builtin___snprintf_chk’ output 2 bytes into a destination of size 1 54 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 55 | __glibc_objsize (__s), __fmt, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 56 | __va_arg_pack ()); | ~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <string.h> #include <stdlib.h> int main(void){ char *str = malloc(101); scanf("%s",str); int len = strlen(str); char *p = str; int ans = 0; for(int i = 0;i< len;i++){ if(p[i] >= '0' && p[i] <= '9'){ int tmp = 0; // int型からchar型に変換 snprintf(p[i], 1, "%d", tmp); ans += tmp; } } }