Java大数简单题---Yet another A + B

news/2024/7/4 14:54:21

PracticeGym 100735I

Description
Statements

You are given three numbers. Is there a way to replace variables A, B and C with these numbers so the equality A + B = C is correct?

Input

There are three numbers X1, X2 and X3 (1 ≤ Xi ≤ 10100), each on a separate line of input.

Output

Output either “YES”, if there is a way to substitute variables A, B and C with given numbers so the equality is correct, or “NO” otherwise.

Sample Input
Input
1
2
3
Output
YES
Input
1
2
4
Output
YES
Input
1
3
5
Output
NO

可以用高精度加法,也可以用Java大数直接做;

给出Java 的代码:

import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        BigInteger a,b,c;
        Scanner in = new Scanner(System.in);
        a = in.nextBigInteger();
        b = in.nextBigInteger();
        c = in.nextBigInteger(); 
        if(a.add(b).equals(c))
        {   
            System.out.println("YES");
            System.exit(0);
        }
        if(a.add(c).equals(b))
        {   
            System.out.println("YES");
            System.exit(0);
        }
        if(b.add(c).equals(a))
        {   
            System.out.println("YES");
            System.exit(0);
        }
        if(a.add(a).equals(b))
        {
            System.out.println("YES");
            System.exit(0);
        }
        if(a.add(a).equals(c))
        {
            System.out.println("YES");
            System.exit(0);
        }
        if(b.add(b).equals(a))
        {
            System.out.println("YES");
            System.exit(0);
        }
        if(b.add(b).equals(c))
        {
            System.out.println("YES");
            System.exit(0);
        }
        if(c.add(c).equals(a))
        {
            System.out.println("YES");
            System.exit(0);
        }
        if(c.add(c).equals(b))
        {
            System.out.println("YES");
            System.exit(0);
        }
        System.out.println("NO");
    }
} 

仅代表个人观点,欢迎交流探讨,勿喷~~~

这里写图片描述

PhotoBy:WLOP

http://weibo.com/wlop


http://www.niftyadmin.cn/n/2246212.html

相关文章

Cisco HyperFlex 多区域上联(Disjoint Networks Upstream)

Cisco HyperFlex 多区域上联(Disjoint Networks Upstream)Deploy Layer 2 Disjoint Networks Upstream in End Host Mode for HyperFlex一般意义上的HX平台是部署在大二层环境中,不同vlan跑不同的功能(data,mgt&#x…

Restore 数学题,水题(转)

C - Restore Time Limit:25000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100735E Description standard input/output Statements Given a matrix A of size N * N. The rows are numbered from 0 to N-1, the column…

unity实战 手机屏幕适配

使用背景 为了在UI中使用特效层,项目Canvas采用了Screen Space-Camera类型 UI的Scale Mode 选择的是Scale With Screen Size 的Expand,画布大小填的是1334, 750 在该选择下,会自动根据分辨率适配宽度/高度。 自动适配的规则是: 屏…

八皇后问题---递归回溯

每次需要满足的条件&#xff1a;abs(x[j]-x[k])abs(j-k) || x[j]x[k] #include <iostream> #include <cmath> using namespace std; const int num8; int sum0; int x[num]{0}; bool place (int k) {for(int j1;j<k;j){if(abs(x[j]-x[k])abs(j-k)||x[j]x[k])re…

容器监控实践—cAdvisor

概述 为了解决docker stats的问题(存储、展示)&#xff0c;谷歌开源的cadvisor诞生了&#xff0c;cadvisor不仅可以搜集一台机器上所有运行的容器信息&#xff0c;还提供基础查询界面和http接口&#xff0c;方便其他组件如Prometheus进行数据抓取&#xff0c;或者cadvisor inf…

染陌足迹——SeeConf2019

水文预警&#xff01;&#xff01;多图预警&#xff01;&#xff01; 听了一整天&#xff0c;每位讲师的演讲都十分精彩&#xff0c;每个主题都能给我从另一个角度的思考与启迪&#xff0c;大部分主题都是以未来的交互设计作为维度来展开思考与探讨&#xff0c;以故事或者事例的…

Java的四种线程池的使用,以及自定义线程工厂

四种线程池四种线程池分别是&#xff1a;newCachedThreadPool、newFixedThreadPool 、newScheduledThreadPool 和newSingleThreadExecutor &#xff0c;下面对这几个线程池一一讲解。newCachedThreadPool&#xff1a;可缓存的线程池源码&#xff1a;public static ExecutorServ…

30K iOS程序员的简述:如何快速进阶成为高级开发人员 ...

前言&#xff1a; 本篇文章适用于所有在这个行业已经有了几年时间后想要在职业生涯中取得突破的开发人员&#xff0c;编程人员和程序员&#xff08;或者你可能刚刚开始&#xff0c;但希望你能看到你的路径&#xff09; 本文适合那些有着简单愿望的人&#xff1a;你想成为一名高…