1060 Are They Equal (25 point(s))

#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int len;
string tran(string s, int& n) {
	while(s.length() && s[0] == '0') s.erase(s.begin()); // 去除首部0 
	if(s[0] == '.') { // 小数 
		s.erase(s.begin());
		while(s.length() && s[0] == '0') {
			s.erase(s.begin());
			--n;
		}
	}else { //  > 1 
		for(int i = 0; i < s.length() && s[i] != '.'; ++i) ++n;
		if(s.length() > n) s.erase(s.begin() + n); // 可能是i >= s.length()退出  
	}
	if(s.length() == 0) n = 0; // 0.0的情况 
	string res = "";
	for(int i = 0; i < len; ++i) //
		if(i < s.length()) res += s[i];
		else res += "0";
	return res;
} 
int main() {
	string a, b;
	int n, alen = 0, blen = 0;
	cin >> len >> a >> b;
	a = tran(a, alen); b = tran(b, blen);
	if(a == b && alen == blen) printf("YES 0.%s*10^%d", a.c_str(), alen);
	else printf("NO 0.%s*10^%d 0.%s*10^%d", a.c_str(), alen, b.c_str(), blen);
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值