您的位置:首页 > 其它

HDU 2054 A == B ? 字符串处理

2014-10-31 22:05 357 查看

A == B ?

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 63662 Accepted Submission(s): 9961



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


/*
HDU 2054 字符串处理 
刚开始没看懂 看了下别人的 这题不好 啥都没说明
有人说有+ -号 但是好像没有 
去除前置的的0和小数点后不为零数字后面的0

0000.1   0.1000000
.1     0.1
000.000     0
123456789123456789 123456789123456789
000001000.  1000
*/
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
void change(string &str)
{
	if(strchr(str.c_str(), '.' ) )  
    {  
        int last=str.length();  
        while(str[--last]=='0') 
			str.erase(last,1); //删除后置0  
        if(str[last]=='.')
			str.erase(last,1) ; //若全为0,删除小数点  
    }  
    while(str[0]=='0')//前置0的处理  
    {  
        if(str.length()!=1) 
			str.erase(0,1);//若全为0,则保存一个0  
        else return;  
    }  
}
int  main()
{
	string num1,num2;
	while(cin>>num1>>num2)
	{
		change(num1);
		change(num2);
		if(num1.compare(num2)==0) 
			cout<<"YES"<<endl;  
        else 
			cout<<"NO"<<endl;  
		
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: