栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

NEC Programming Contest 2021(AtCoder Beginner Contest 229) B - Hard Calculation

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

NEC Programming Contest 2021(AtCoder Beginner Contest 229) B - Hard Calculation

题目链接:B - Hard Calculation (atcoder.jp)

Problem Statement

You 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.

Constraints
  • A and B are integers.
  • 1≤A,B≤1018

Input

Input is given from Standard Input in the following format:

A B
Output

If the calculation does not involve a carry, print Easy; if it does, print Hard.


Sample Input 1 
229 390
Sample 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 9876543210
Sample 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

#include
using 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;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/604837.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号