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的更多相关文章

  1. 软件包管理 之 Fedora/Redhat 在线安装更新软件包,yum 篇 ── 给新手指南

    在本文中,我们主要解介绍 Fedora core 4.0 通过软件包管理工具yum来在线安装更新软件:关于apt工具应用,我们会在另外一篇中介绍: 一. yum 的使用:有些初学Linux的弟兄可能问 ...

  2. Tokyo Tyrant(TTServer)系列(一)-介绍和安装

    Tokyo Cabinet 是日本人Mikio Hirabayashi 开发的一款DBM 数据库,该数据库读写很快.哈希模式写入100 万条数据仅仅需0.643 秒.读取100 万条数据仅仅需0.77 ...

  3. 不同linux版本下内核/系统/软件的安装及查询

    (一)先介绍下使用apt-get 和使用yum 包管理工具的不同用法: 1.先看yum(redhat) yum的配置文件是/etc/yum.conf 更新:yum update 安装:yum inst ...

  4. Scoop - 在Windows命令行上进行程序安装

    2019-01-28  22:49:21 资料来源自Scoop官方网站以及github上的帮助文档 如果有疑惑或者觉得文章有错误请留言以帮助改正 补充内容(2019-04-09 21:11:36):不 ...

  5. [转帖]如何获得一个RAC Oracle数据库(从Github - oracle/docker-images) - 本地版 ---暂时未做实验.

    如何获得一个RAC Oracle数据库(从Github - oracle/docker-images) - 本地版 2019-11-09 16:35:30 dingdingfish 阅读数 32更多 ...

  6. -Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HO 解决办法

    最近在使用maven,项目测试的时候出现了这么一个错.-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2 ...

  7. SQL Server 合并复制遇到identity range check报错的解决

        最近帮一个客户搭建跨洋的合并复制,由于数据库非常大,跨洋网络条件不稳定,因此只能通过备份初始化,在初始化完成后向海外订阅端插入数据时发现报出如下错误: Msg 548, Level 16, S ...

  8. SharePoint 2103 Check user permission on list

    一.需求: check user 对SharePoint list 的permission 代码如下: private static string GetListPermission(SPList l ...

  9. 用SVN check out项目后第三方库丢失

    曾经用Cornerstone check out 一份项目下来,但其中第三方.a库始终丢失,项目报错,研究后找到了以下解决方法: 首先,Xcode默认忽略.a 文件.所以无法提交到svn服务器,但是很 ...

随机推荐

  1. OpenCV---轮廓发现

    推文:OpenCV-Python教程(11.轮廓检测) 轮廓发现 是基于图像边缘提取的基础,寻找对象轮廓的方法,所以边缘提取的阈值选定会影响最终轮廓的发现 相关API findContours 发现轮 ...

  2. 在使用Hibernate save()方法的时候 报错: org.hibernate.exception.ConstraintViolationException:could not perform addBath

    org.hibernate.exception.ConstraintViolationException:could not perform addBath 错误可能原因:实体属性的值与数据库字段类型 ...

  3. MySQl学习-——Mysql体系结构与Mysql存储引擎

    Mysql体系结构与Mysql存储引擎 Mysql体系结构 mysql体系结构图:

  4. 母版页 VS shtml—ASP.NET细枝末节(3)

    这算是html的重用吧? 网页很多地方长得一样,也有不一样的地方. 把网页中一样的地方,提取出来,形成一个文档. 在其他网页中引用,是网站开发的一个传统的思维. 当然不同的技术有不同的表现形式. 例如 ...

  5. PHP做文件限速下载

    <?php include("DBDA.class.php"); $db = new DBDA(); $bs = $_SERVER["QUERY_STRING&qu ...

  6. BestCoder Round92

    题目链接:传送门 HDU 6015-6018 解题报告:传送门 HDU6015 Skip the Class  Accepts: 678  Submissions: 1285  Time Limit: ...

  7. favico.js笔记

    1. favicon.js是什么 一个js库可以使用徽标.图像.视频等来设置网页的favicon,即网页标题栏上的小图标. 2. 如何使用 2.1 使用徽标 basic demo: <!DOCT ...

  8. bzoj 1143 二分图最大独立集

    我们可以将一个点拆成两个点x,y,那么如果存在一条i->j的路径,我们就连接xi,yj,那么答案就是n-最大匹配数. 因为i->j所以对于i与j只能选一个,那么我们只需要求出来二分图的最大 ...

  9. 使用Bash时的几点总结

    作为一个天天与Linux打交道,并以此为生的Linux运维工程师,最常用的工具性语言恐怕就是shell了, 而对于大多数的Linux和一些类Unix而言,其默认的shell就是Bash.使用Bash一 ...

  10. 《STL源码剖析》读书笔记

    转载:https://www.cnblogs.com/xiaoyi115/p/3721922.html 直接逼入正题. Standard Template Library简称STL.STL可分为容器( ...