1060. Are They Equal (25)

测试用例中输入的数据不标准,例如000.123  000123  另外需要注意0的情况

#define  _CRT_SECURE_NO_WARNINGS 
#include<string>
#include<string.h>
#include<vector>
#include<map>
#include<stack>
#include<iostream>
#include<set>
#include<algorithm>
#include<stdio.h>  
using namespace std;  
bool isPrime(int num)
{
int range = sqrt(num) + 1;
for (int i = 2; i < range; i++)
if (num%i == 0)
return false;
return true;
}
void standard(string a,int &num,string &after)
{
num = 0; 
after = "0.";
int i = 0;
while (a[i] == '0')
{
i++;
}
if (a[i] == '.')
{  
for (i ++; i < a.size(); i++)
{
if (a[i] != '0')
{
after = after+ a.substr(i);
break;
}
else
{
num--;
}

if (after == "0.")
{
after += "0";
num = 0;
}
}
else
{
for (; i < a.size(); i++)
{
if (a[i] == '.')
{
after =after + a.substr(i + 1);
break;
}
else
{
num++;
after += a[i];
}
}



return;
}
int main()
{
int N;
cin >> N;
string a, b;
cin >> a >> b;
int num_a, num_b;
string after_a , after_b;
standard(a, num_a, after_a);
standard(b, num_b, after_b);
while (after_a.size() < N + 2)

after_a += "0";
}
while (after_b.size() < N + 2)
{
after_b += "0";
}
bool btrue = true;
if (num_a != num_b)
{
btrue = false;
}
else
{
if (after_a.substr(0, N + 2) != after_b.substr(0, N + 2))
btrue = false;
}
if (btrue)
{
printf("YES %s*10^%d", after_a.substr(0, N + 2).c_str(), num_a);
}
else
{
printf("NO %s*10^%d %s*10^%d", after_a.substr(0, N + 2).c_str(), num_a, after_b.substr(0, N + 2).c_str(), num_b);
}
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值