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服务器,但是很 ...
随机推荐
- [机器学习]-PCA数据降维:从代码到原理的深入解析
&*&:2017/6/16update,最近几天发现阅读这篇文章的朋友比较多,自己阅读发现,部分内容出现了问题,进行了更新. 一.什么是PCA:摘用一下百度百科的解释 PCA(Prin ...
- CodeBlocks的常用快捷键
CodeBlocks常用操作快捷键 编辑部分: Ctrl + A:全选 Ctrl + C:复制 Ctrl + X: 剪切 Ctrl + V:粘贴 Ctrl + Z:撤销 Ctrl + S:保存 Ctr ...
- java中集合去重2
1.对集合中的自动定义的对象去重: 自定义Person类,同时复写hashCode和equals方法 package collection; public class Person { private ...
- 搭建简单的node+express+mongodb项目
安装 首先要确保已经安装了 Node.js,接下来创建一个目录,然后进入此目录并将其作为当前工作目录. mkdir myapp cd myapp 通过 npm init 命令为应用创建一个 packa ...
- Lua的各种资源1
Libraries And Bindings LuaDirectory > LuaAddons > LibrariesAndBindings This is a list of l ...
- 【代码优化】调用optional delegates的最佳方法
[转载请注明出处]http://www.cnblogs.com/lexingyu/p/3932475.html 本文是以下两篇blog的综合脱水,感谢两位作者为解放码农生产力所做的深入思考=.= Sm ...
- php通过composer添加一个包以后,无法通过git将这个包的代码文件提交上去
实际上是因为 vender 包中包含 有.git 文件,是composer 下载时下载了 该项目的github源码. 就是参数 源码优先 --prefer-source composer update ...
- Unity MMO 参考数值
贴图格式: iOS :RGBA 32 (pvrtc 4 ) Android : RGB Compresed ETC 4 或 RGBA 32 . DrawCall: 总计Drawcall 平均 100 ...
- python3学习笔记.2.基础
1.编码 默认编码是 utf-8 # -*- coding: utf-8 -*- 2.注释 单行注释 # 多行注释,用三个单引号或双引号 3.关键字 可在交互窗口查询. >>> i ...
- PyCharm 自定义文件和代码模板
PyCharm提供了文件和代码模板功能,可以利用此模板来快捷新建代码或文件.比如在PyCharm中新建一个html文件,新的文件并不是空的,而是会自动填充了一些基础的必备的内容,就像这样: <! ...