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. MVC的验证码

    后台: /// <summary> /// 创建验证码的图片 /// </summary> /// <param name="validateCode" ...

  2. [dp uestc oj] G - 邱老师玩游戏

    G - 邱老师玩游戏 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  3. HTML5中的Web Workers

    https://www.cnblogs.com/yanan-boke/p/6954390.html https://segmentfault.com/a/1190000014938305 HTML5 ...

  4. python 搜集参数

    def print_params(*params): print(params) print_params('Testing')print_params(1,2,3) #参数前的星号将所有值放置在同一 ...

  5. springboot 修改文件上传大小限制

    springboot 1.5.9文件上传大小限制spring:http:multipart:maxFileSize:50MbmaxRequestSize:50Mb springboot 2.0文件上传 ...

  6. The expected type was 'System.Int64' but the actual value was null.”

    System.InvalidOperationException:“An exception occurred while reading a database value for property ...

  7. css3 设置滚动条的样式

    ::-webkit-scrollbar { width: 14px; height: 14px; } ::-webkit-scrollbar-track, ::-webkit-scrollbar-th ...

  8. 【mysql】mysql has gone away

    原文 http://www.jb51.net/article/23781.htm MySQL server has gone away 问题的解决方法 投稿:mdxy-dxy 字体:[增加 减小] 类 ...

  9. MySQL迁移升级解决方案

    任务背景 由于现有业务架构已不能满足当前业务需求,在保证数据完整的前提下,现需要将原有数据库迁移到另外一台单独的服务器上,在保证原有服务正常的情况下,将原有LAMP环境中mysql数据库版本5.6.3 ...

  10. python3 简单服务器监控,自动发送邮件

    import smtplibfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartimpo ...