题目链接:B - Hard Calculation (atcoder.jp)
Problem StatementYou are given positive integers A and B.
Let us calculate A+B (in decimal). If it does not involve a carry, print Easy; if it does, print Hard.
- A and B are integers.
- 1≤A,B≤1018
Input
Input is given from Standard Input in the following format:
A BOutput
If the calculation does not involve a carry, print Easy; if it does, print Hard.
Sample Input 1
229 390Sample Output 1
Hard
When calculating 229+390, we have a carry from the tens digit to the hundreds digit, so the answer is Hard.
Sample Input 2
123456789 9876543210Sample Output 2
Easy
We do not have a carry here; the answer is Easy.
Note that the input may not fit into a 32-bit integer.
题意:问a+b的过程中是否产生进位,如果有输出hard,否则easy
思路:每一位都提取出来来进行运算。直到a为0或者b为0
#includeusing namespace std; int main(){ long long a, b; cin >> a >> b; bool flag = 0; while(a && b && !flag){ int ans = a % 10; int cnt = b % 10; if(ans + cnt >= 10){ flag = 1; break; } a /= 10; b /= 10; } if(flag){ cout << "Hard" << endl; }else{ cout << "Easy" << endl; } return 0; }



