#148. 条件求和:位数判断

    ID: 148 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatLogic-1gesp1条件结构数学基础

条件求和:位数判断

Conditional Sum

Background

Congcong is learning about number operations. He encountered an interesting summation problem that requires determining the final result based on the number of digits in the sum.

Problem Description

Given two non-negative integers aa and bb, return their sum, so long as the sum has the same number of digits as aa. If the sum has more digits than aa, just return aa without bb. (Note: one way to compute the number of digits of a non-negative integer nn is to convert it to a string with String.valueOf(n) and then check the length of the string.)

Input Format

Input is given from standard input in the following format.

aa bb

Output Format

Output is printed to standard output in the following format.

[result]

Sample

2 3
5
8 3
8
8 1
9

Sample Explanation

Sample 1: a=2,b=3a=2, b=3. a+b=5a+b=5. 22 has 1 digit, and 55 also has 1 digit. The number of digits is the same, so return 55. Sample 2: a=8,b=3a=8, b=3. a+b=11a+b=11. 88 has 1 digit, but 1111 has 2 digits. The sum has more digits than aa, so return 88. Sample 3: a=8,b=1a=8, b=1. a+b=9a+b=9. 88 has 1 digit, and 99 also has 1 digit. The number of digits is the same, so return 99.

Constraints

Time limit: 1 second, Memory limit: 1024 KiB for each test case.