A == B ?

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

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

第一次看别人的代码AC的,这次自己用C++string类函数AC的,此题虽然不考虑正负号,但是代码显然还是有正负号的缺陷,加入正负号感觉更加麻烦,而且对结果会有副作用,因此先不考虑正负号了。

代码:

#include<iostream>
#include<string>
using namespace std;
string qianzero(string a)//前导0检查
{
if(a.find_first_not_of('0')!=string::npos)
{
a.erase(0,a.find_first_not_of('0'));//去除前导0,并且连小数点一并去除了(小数点也属于非零)
}
return a;
}
string houzero(string a)//后导0检查
{
int l=-1,i;
if(a.find('.')!=string::npos)//若有小数点则继续判断
{
for(i=a.size()-1;i>=0;i--)
{
if(i==a.find('.'))//若非零数字超过了小数点,则只能截取到【小数点~最后一位】为止
{
l=i-1;
break;
}
if(a[i]!='0'&&a[i]!='.')//否则截取到【非零数字~最后】一位
{
l=i;
break;
}
}
if(l==-1)//若根本找不到小数点,则直接返回(即不可以动后面的0)
{
return a;
}
a.erase(l+1,a.size()-1);//去掉后面的0
}
return a;
}
string point(string a)//检查并将实际为0的各种类型归一为“0”
{
int i;
for (i=0; i<a.size(); i++)
{
if(a[i]!='0'&&a[i]!='.')//若发现某个字符不是0且不是小数点,则此数一定不等于0,返回
return a;
}
return a="0";//否则干脆变成“0”
}
int main(void)
{
string a,b;
while(cin>>a>>b)
{
a=qianzero(a);
b=qianzero(b);
a=houzero(a);
b=houzero(b);
a=point(a);
b=point(b);
//cout<<a<<' '<<b<<'\n'<<endl;
if(a==b)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
}

HDU——2054A==B?的更多相关文章

  1. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  3. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  4. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  5. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  6. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  7. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  8. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

  9. hdu 4329

    problem:http://acm.hdu.edu.cn/showproblem.php?pid=4329 题意:模拟  a.     p(r)=   R'/i   rel(r)=(1||0)  R ...

随机推荐

  1. OpenGL小试牛刀第一季

    效果截图:代码展示:using System;using System.Collections.Generic;using System.ComponentModel;using System.Dat ...

  2. 2018.5.9 Oracle数据库查询命令

    0.查询所有数据(最简单,但是时间很久) select * from emp; Result: EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ----- - ...

  3. Ubuntu 忘记root user密码 关闭图形界面

    忘记root密码 删除recovery nomodeset 才删除的后面添加 quiet splash rw init=/bin/bash.然后按F10, 启动 忘记User密码 http://blo ...

  4. SC || Chapter6 复习向 面向可维护性 我哭了

    高内聚低耦合 高内聚:一个模块内部各个元素彼此结合的紧密程度,一个软件模块是由相关性很强的代码组成,只负责一项任务,也就是常说的单一责任原则 低耦合:各模块间相互联系紧密程度,模块间接口的复杂性.调用 ...

  5. 安装IAR ewarm

    一  安装准备 (ST方案) 1 嵌入式集成开发环境IAR ewarm 5.41 2 J-Link4.20 3 emberznet-4.3.0协议栈安装包 option1:tools - stm32软 ...

  6. 在ASP.NET项目中的web.config文件里配置数据库连接并在程序代码中获取连接字符串

      1.在<connectionStrings> 标签里添加连接 <connectionStrings> <add name="ConnectionName&q ...

  7. NSCharacterSet去除字符串中的空格、删除指定\任意字符集

    一.去除首尾的空格 /** 1.去除首尾的空格*/ NSString *strMsg=@" 简书作者:CoderZb "; NSString *strResult = [strMs ...

  8. Clang提供的办法

    1.方法弃用警告 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarati ...

  9. javascript实现原生ajax的几种方法介绍

    自从javascript有了各种框架之后,比如jquery,使用ajax已经变的相当简单了.但有时候为了追求简洁,可能项目中不需要加载jquery这种庞大的js插件.但又要使用到ajax这种功能该如何 ...

  10. Python PyAudio 安装使用

    Python PyAudio安装: Python3.7 无法安装pyaudio pip install pyaudio提示error: Microsoft Visual C++ 14.0 is req ...