码迷,mamicode.com
首页 > 编程语言 > 详细

HD-ACM算法专攻系列(4)——A == B ?

时间:2017-06-09 13:23:04      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:--   images   pre   img   ret   space   main   name   ios   

题目描述:

技术分享

源码:

/**/
#include"iostream"
#include"string"
using namespace std;

string Standard(string str)
{
	int start;
	int len = str.length();
	char * p = new char[len + 2];
	start = 0;
	if(str[0] == ‘-‘ || str[0] == ‘+‘)
	{
		p[0] = str[0];
		start = 1;
	}
	else 
	{
		p[0] = ‘+‘;
	}
	for(int i = start; i < len; i++)
	{
		if(str[i] == ‘0‘)
		{
			start++;
		}
		else
		{
			break;
		}
	}
	bool hasDot = false;
	for(int i = start; i < len; i++)
	{
		if(str[i] == ‘.‘)
		{
			hasDot = true;
			break;
		}
	}
	if(hasDot)
	{
		for(int i = len - 1; i >= start; i--)
		{
			if(str[i] == ‘0‘)
			{
				len--;
			}
			else
			{
				break;
			}
		}
	}
	int index = 1;
	if(str[len - 1] == ‘.‘)
	{
		len--;
	}
	for(int i = start; i < len; i++)
	{
		p[index++] = str[i];
	}
	p[index] = ‘\0‘;
	return string(p);
}

int main()
{
	string a, b;
	while(cin>>a>>b)
	{
		a = Standard(a);
		b = Standard(b);
		if(a == b)
		{
			cout<<"YES"<<endl;
		}
		else
		{
			cout<<"NO"<<endl;
		}
		
	}
    return 0;
}

  

HD-ACM算法专攻系列(4)——A == B ?

标签:--   images   pre   img   ret   space   main   name   ios   

原文地址:http://www.cnblogs.com/OneForCheng/p/6971469.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!