結果

問題 No.289 数字を全て足そう
ユーザー kachipan
提出日時 2023-06-22 16:55:50
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 617 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 28,928 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-29 23:52:15
合計ジャッジ時間 763 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

int main()
{
	char str[10000] = "";
	int ans = 0;
	scanf("%s", str, sizeof(str));

	for (int i = 0;str[i] != '\0';i++)
	{
		if (str[i] == '1')
		{
			ans += 1;
		}
		else if (str[i] == '2')
		{
			ans += 2;
		}
		else if (str[i] == '3')
		{
			ans += 3;
		}
		else if (str[i] == '4')
		{
			ans += 4;
		}
		else if (str[i] == '5')
		{
			ans += 5;
		}
		else if (str[i] == '6')
		{
			ans += 6;
		}
		else if (str[i] == '7')
		{
			ans += 7;
		}
		else if (str[i] == '8')
		{
			ans += 8;
		}
		else if (str[i] == '9')
		{
			ans += 9;
		}
	}

	printf("%d", ans);

	return 0;
}
0