Check whether a + b = c or not after removing all zeroes from a,b and c
Check whether a + b = c or not after removing all zeroes from a,b and c
Given two integers a and b, the task is to add them to get c. After that remove zeroes from a, b and c and check for modified values if a + b = c then return “YES” else return “NO”.
Input: a = 101, b = 102
Output: YES
101 + 102 = 203.
After removing all zeroes from a, b and c, a = 11, b = 12 and c = 23
Now check if a + b = c i.e. 11 + 12 = 23 . So print Yes.Input: a = 105, b = 108
Output: NO
After removing all zeroes a + b!= c, therefore the output is NO.
/**
* SolutionRemoveZero class
* https://www.geeksforgeeks.org/check-whether-a-b-c-or-not-after-removing-all-zeroes-from-ab-and-c/
* @author libin
* @date 2019/1/25 10:57
*/
public class SolutionRemoveZero {
public static int removeZero(int n) {
int res = 0;
int d = 1;
while (n > 0) {
if (n % 10 != 0) {
res += (n % 10) * d;
d *= 10;
}
n /= 10;
}
return res;
}
public static boolean isEqual(int a, int b) {
if (removeZero(a) + removeZero(b) == removeZero(a + b)) {
return true;
}
return false;
}
public static void main(String[] args) {
int a = 101, b = 102;
if (isEqual(a, b) == true) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
}
更多请看:https://www.geeksforgeeks.org/check-whether-a-b-c-or-not-after-removing-all-zeroes-from-ab-and-c/
Check whether a + b = c or not after removing all zeroes from a,b and c的更多相关文章
- 软件包管理 之 Fedora/Redhat 在线安装更新软件包,yum 篇 ── 给新手指南
在本文中,我们主要解介绍 Fedora core 4.0 通过软件包管理工具yum来在线安装更新软件:关于apt工具应用,我们会在另外一篇中介绍: 一. yum 的使用:有些初学Linux的弟兄可能问 ...
- Tokyo Tyrant(TTServer)系列(一)-介绍和安装
Tokyo Cabinet 是日本人Mikio Hirabayashi 开发的一款DBM 数据库,该数据库读写很快.哈希模式写入100 万条数据仅仅需0.643 秒.读取100 万条数据仅仅需0.77 ...
- 不同linux版本下内核/系统/软件的安装及查询
(一)先介绍下使用apt-get 和使用yum 包管理工具的不同用法: 1.先看yum(redhat) yum的配置文件是/etc/yum.conf 更新:yum update 安装:yum inst ...
- Scoop - 在Windows命令行上进行程序安装
2019-01-28 22:49:21 资料来源自Scoop官方网站以及github上的帮助文档 如果有疑惑或者觉得文章有错误请留言以帮助改正 补充内容(2019-04-09 21:11:36):不 ...
- [转帖]如何获得一个RAC Oracle数据库(从Github - oracle/docker-images) - 本地版 ---暂时未做实验.
如何获得一个RAC Oracle数据库(从Github - oracle/docker-images) - 本地版 2019-11-09 16:35:30 dingdingfish 阅读数 32更多 ...
- -Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HO 解决办法
最近在使用maven,项目测试的时候出现了这么一个错.-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2 ...
- SQL Server 合并复制遇到identity range check报错的解决
最近帮一个客户搭建跨洋的合并复制,由于数据库非常大,跨洋网络条件不稳定,因此只能通过备份初始化,在初始化完成后向海外订阅端插入数据时发现报出如下错误: Msg 548, Level 16, S ...
- SharePoint 2103 Check user permission on list
一.需求: check user 对SharePoint list 的permission 代码如下: private static string GetListPermission(SPList l ...
- 用SVN check out项目后第三方库丢失
曾经用Cornerstone check out 一份项目下来,但其中第三方.a库始终丢失,项目报错,研究后找到了以下解决方法: 首先,Xcode默认忽略.a 文件.所以无法提交到svn服务器,但是很 ...
随机推荐
- tomcat启动 报org.apache.catalina.LifecycleException异常
java 服务器 tomcat启动 报org.apache.catalina.LifecycleException异常 异常代码如下: [2018-05-10 04:45:08,856] Artifa ...
- WPF:ComboBox使用XmlDataProvider做级联
程序功能: 使用ComboBox做级联,数据源为XML文件,适合小数据量呈现 程序代码: <Window x:Class="WpfApplication1.LayouTest" ...
- [Mac]一些命令技巧
Git相关 mac下git默认不区分大小写,通过下面脚本可以改变 #!/bin/bash # 让git区分大小写 cd 'path-of-project' git config core.ignore ...
- 巧用margin/padding的百分比值实现高度自适应
原文:https://segmentfault.com/a/1190000004231995 一个基础却又容易混淆的css知识点 本文依赖于一个基础却又容易混淆的css知识点:当margin/padd ...
- 生成验证码tp
js里拼接随机数 页面上链接 去掉后缀名
- 使用迭代法穷举1到N位最大的数
这是何海涛老师剑指offer上面第12题,这题首先注意不能使用整数int型作为操作对象,因为N很大时明显会溢出.这种大数据一般都是使用的字符串来表示. 直接法就是:1.针对字符串的加法,涉及循环进位及 ...
- 关于linux系统如何实现fork的研究(一)【转】
转自:http://www.aichengxu.com/linux/4157180.htm 引言 fork函数是用于在linux系统中创建进程所使用,而最近看了看一个fork()调用是怎么从应用到gl ...
- elasticsearch删除索引报错【原】
如果elasticsearch删除索引报错 curl -X DELETE 'http://10.73.26.66:9200/httpd-34-2017.08.15' {"error" ...
- 使用 Xtrabackup 在线对MySQL做主从复制【转】
1. 说明 1.1 xtrabackup mysqldump对于导出10G以下的数据库或几个表,还是适用的,而且更快捷.一旦数据量达到100-500G,无论是对原库的压力还是导出的性能,mysqldu ...
- java中String的==和equals的区别
首先看代码1: public static void main(String[] args) { List<String> list=new ArrayList<String> ...