HDU 2054 A == B ?

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

       A == B ?

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 62521    Accepted Submission(s): 9811

Problem Description

Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".

Input

each test case contains two numbers A and B.

Output

for each case, if A is equal to B, you should print "YES", or print "NO".

Sample Input

1 2 

2 2 

3 3 

4 3

Sample Output

NO 

YES 

YES 

NO

【思路分析】

一看就是超级水题,可是坑却特别深。。。。。。

应该注意以下几点细节:

1 题中没有说明两个数的类型,所以可能会出现连__int64/long long都存不下的数,因此需要字符串来存储数据(大数),或者使用java的大数秒A;

2 注意前导零以及后导零 即 000001 和1相等,1.000000和1相等,因此需要将多余的零以及小数点给去掉;

3 注意-0 和 0 是相等的  所以数据中只有0、.、-、+时两数是相等的

代码如下:

#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <string>

#include <algorithm>

#include <cstring>

#include <cmath>

using namespace std;

void change_front(string &str)

{

    int p1,p2;

    p1=p2=0;

    if (str[0] == '-')

    {

        p1++;

        p2=p1;

    }

    while (str[p1] == '0')

        p1++;

    str.erase(p2,p1-p2);

}

void change_back(string &str)

{

    int l=str.length()-1;

    while (str[l] == '0')//排除后导零

        l--;

    while (str[l] == '.')//排除小数点

        l--;

    str.erase(l+1);//删去从l指针后的零、小数点

}

int if_zero(string &str1,string &str2)

{

    int l1=str1.length()-1;

    int l2=str2.length()-1;

    int x=1;

    int y=1;

    for (int i=0;i<=l1;i++)

        if (str1[i] != '0' && str1[i] != '.' && str1[i] != '+' && str1[i] != '-')

    {

        x=0;

        break;

    }

    for (int i=0;i<=l2;i++)

        if (str2[i] != '0' && str2[i] != '.' && str2[i] != '+' && str2[i] != '-')

    {

        y=0;

        break;

    }

    if (x && y)

       x=1;

    return x;

 

}

int main()

{

    string a,b;

    int la,lb;

    while (cin>>a>>b)

    {

        if (if_zero(a,b))

        {

            cout<<"YES"<<endl;

            continue;

        }

        change_front(a);

        change_front(b);

        la=a.length()-1;

        lb=b.length()-1;

        for (int i=la;i>=0;i--)

            if (a[i] == '.')//若为小数,则进行后导零以及小数点的处理

        {

            change_back(a);

            break;

        }

        for (int i=lb;i>=0;i--)

            if (b[i] == '.')

        {

            change_back(b);

            break;

        }

        if (a == b)

            cout<<"YES"<<endl;

        else

            cout<<"NO"<<endl;

    }
    return 0;

}


 

 

另外搜了一个java的代码 看完之后默默地流泪@-@

import java.math.BigDecimal;

import java.util.*;

public class Main{

public static void main(String[] args){

Scanner sc = new Scanner(System.in);

BigDecimal a,b;

while(sc.hasNext()){

a=sc.nextBigDecimal();

    b=sc.nextBigDecimal();

    if(a.compareTo(b)==0)

        System.out.println("YES");

    else

        System.out.println("NO");    

}

}

}

 


hdu 2007 平方与立方 平方与立方<br />Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)<br />Total Submission(s): 29405    Accepted Submission(s): 8250<br /><br /><br />Problem Description给定一段连续的整数,求出他们中所有偶数的平方以及所有奇数的立方。<br /> <br /> Input输入数据包含 阅读详情

相关推荐

作业题,编写两个类:AB,A创建的对象可以计算两个正整数的最大公约数,B创建的对象可以计算两个数的最小公倍数,要求:B类中有一个成员变量是A类声明的对象

import java.util.*; class A { public int f(int min,int max){ if(min==0){      return max;     }else{      return f(max%min,min);     }    } class B { A a=new A(); public int g(int min,int

bao745077267的专栏 8387

2016ACM/ICPC亚洲区青岛站(区域赛练习)

比赛链接:https://cn.vjudge.net/contest/257341 目录 A - Relic Discovery B—Pocket Cube C - Pocky D-Lucky Coins G-Coding Contest A - Relic Discovery Recently, paleoanthropologists have found historical...

LMengi000的博客 1847

KMP-看毛片算法 c++

kmp算法包括两步 1,计算next数组,即对要寻找的字符串标记值,例如abcabc,这边有六个字符,从a开始,将每一个字符与这个字符串开头开始匹配,第一个字符标记为0,第二个字符为b,明显与字符串开头a不相等,因此标记为0。第四个字符为a,与字符串开头a相等,因此标记为1,第五个字符为b,但他前面的字符被标记为1,因此第五个字符要与第1+1个字符相比较,如果相似,则标记为前一个字符标记的值+1

My__Code的博客 7928

hdu 2054 A==B?

hdu  2054  A==B?             题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2054 模拟(似乎已经可以不算太水了) 题目大意:输入两个数,判断两个数是否相等,相等输出YES,反之NO。 题目分析:小数点,会有的;正负号,会有的;前导0,会有的;小数点后的末尾0,也会有的(好像就这么些了,也不多,是吧)。我的思想是把

slicer的技术交流栈 773

HDU2054 A == B ?

问题链接:HDU2054 A == B ?。 问题简述:输入两个数,比较两个数的大小,相等的话输出"YES",不等的话输出"NO"。 问题分析:可能是一个大数,需要特殊处理。如果没有小数点,就可以直接进行字符串比较,如果有小数点,则需要处理小数点后多余的"0",即删除那些"0",然后再进行字符串比较。 程序说明:编写函数mystrchange()对大数进行调整,...

weixin_34408624的博客 101

HDU OJ 2054 A == B ?

A == B ? Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 109259    Accepted Submission(s): 17479 Problem Description Give you two n

PasserbyQk 齐凯 527

HDU - 2054 A == B ?

Description Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO". Input each test case contains two numbers A and B. Output for each case, if A is equal to...

一定要站在自己热爱的生活里闪闪发光 3万+

HDU 2054 A == B ?

题目:http://acm.hdu.edu.cn/showproblem.php?pid=2054   题意:给两个数,判断这两个数是否相等。没有范围没有填写规则   代码: 这个是自己写的很长 #include #include int main() { char s1[100000]; char s2[100000]; int t;

努力ing!~ 2129

hdu2054A == B ?

A == B ? Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 65188    Accepted Submission(s): 10191 Problem Description Give you two number

千言万语ROOM 2021

HDU-2054 A==B?

Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO". 越

野生 827

A == B ? HDU - 2054

原题链接 总结:这个题WA了好多次,从一开始只是简单认为比较两个实数,到后来用字符串表示,由于想得太少而一错再错,总的来说这个题需要注意以下几点: 1.注意正负性 2.注意小数点的存在,这又分为整数+小数点+0后缀,小数两种形式 3.注意前缀0,小数状态下的后缀0,需要把它们删除 4.用C++时,一些情况下,最好用scanfprintf输入输出,别用cincout了,这样可以节省一...

无论多么困难,也要熬下去!!! 379

hdu - 2054 - A == B ?

题意:输入两个数字A, B,如果A等于B,输出YES”,否则输出“NO”。 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2054 ——>>开始以为,好简单呀,直接输入两个string,然后用==判断,一次WA,改用直接输入两个double,然后用==判断,再次WA……原来,这不是那么好过的题!要考虑前导0与有小数点的尾0。不过貌似不用考虑负数

无节操 2557

HDU 2054 A==B

Problem Description Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO".   Input each test case contains two numbers A and B.   Output fo

Crazy_Frog的专栏 5141

hdu 2054 A == B ?

A == B ? Problem Description Give you two numbers A and B, if A is equal to B, you should print "YES", or print "NO". Input each test case contains two numbers A and B. Output for eac...

迷路的博客 264
上一篇: CSU 1460: Kastenlauf
下一篇: HDU 1016 Prime Ring Problem
Spectacules
博客等级 码龄11年 2粉丝 69原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值