#B. 数位之和

    Type: Default 1000ms 256MiB

数位之和

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

题目描述

小 Z 正在做口算练习。老师给出一个正整数 nn,让他算出这个数各个数位上的数字之和。

例如 n=2026n = 2026 时,各位数字依次是 2,0,2,62,0,2,6,它们的和是 2+0+2+6=102+0+2+6=10。

请你写一个程序帮小 Z 算一算。

输入格式

一行一个正整数 nn。

输出格式

一行一个整数,表示 nn 各位数字之和。

2026
10
7
7
1000000
1

数据范围与提示

【样例解释】

  • 样例 1:2+0+2+6=102+0+2+6=10。
  • 样例 2:nn 只有一位,答案就是它本身,77。
  • 样例 3:10000001000000 的各位数字是 1,0,0,0,0,0,01,0,0,0,0,0,0,和是 11。

【数据范围】

对于所有测试数据,保证 1≤n≤1091 \le n \le 10^9。

HIL2026年9月启蒙组

Not Attended
Status
Done
Rule
IOI
Problem
4
Start at
2026-9-28 10:30
End at
2026-10-6 18:30
Duration
200 hour(s)
Host
Partic.
0