#CCBCHBON0000046. Tổng chữ số trước dấu chấm đầu (Sum Digits Before First Period)
Tổng chữ số trước dấu chấm đầu (Sum Digits Before First Period)
Sum Digits Before First Period
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Read ASCII bytes until the first . or EOF, whichever comes first. Sum the numeric values 0..9 of all digit characters read before stopping. Ignore other characters, including spaces and LF. Return zero if no digit occurs. A period need not appear.
Input
An ASCII stream of 0..100000 bytes; a period may be absent.
Output
Print the sum of digit values followed by LF.
Subtasks
-
Subtask 1 (20%): ASCII stream length 0..100 bytes.
-
Subtask 2 (30%): ASCII stream length 0..2000 bytes.
-
Subtask 3 (50%): ASCII stream length 0..100000 bytes.
Examples
Example 1
Input:
a3 b7.90
Output:
10
Explanation:
Add digit values up to the first period or EOF. Exact input: "a3 b7.90"; exact output: "10\n".
Example 2
Input:
abc
Output:
0
Explanation:
Add digit values up to the first period or EOF. Exact input: "abc"; exact output: "0\n".
Example 3
Input:
1
2.34
Output:
3
Explanation:
Add digit values up to the first period or EOF. Exact input: "1\n2.34"; exact output: "3\n".
Example 4
Input:
Output:
0
Explanation:
Add digit values up to the first period or EOF. Exact input: ""; exact output: "0\n".
Note on displayed bytes: \n denotes an actual LF, \t an actual tab and \r an actual CR. The JSON-style Input renderings in explanations are diagnostic only, not extra input characters.