結果
問題 |
No.289 数字を全て足そう
|
ユーザー |
![]() |
提出日時 | 2025-03-03 17:04:12 |
言語 | C (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 357 bytes |
コンパイル時間 | 499 ms |
コンパイル使用メモリ | 24,832 KB |
実行使用メモリ | 8,612 KB |
最終ジャッジ日時 | 2025-03-03 17:04:17 |
合計ジャッジ時間 | 4,311 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 3 |
other | WA * 1 RE * 20 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:16:26: warning: passing argument 1 of ‘snprintf’ makes pointer from integer without a cast [-Wint-conversion] 16 | snprintf(tmp, 1, "%d", p[i]); | ^~~ | | | int 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 ‘int’ 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); | ^~~~~~~~~~~~~~~ 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: warning: null destination pointer [-Wformat-truncation=] 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(tmp, 1, "%d", p[i]); ans += tmp; } } }