PAT 甲级 1060 Are They Equal (25 分)

 

//case 3: 1 0.01 0.009

//case 6: 2 0 0.0

 

#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

struct FORM{
    string d;
    int k;
};
//case 3:1 0.01 0.009
//case 6:2 0 0.0
static struct FORM formStandard(string init,int n)
{
    struct FORM ret;
    bool nozero = false;
    bool point = false;

    ret.d = "";
    ret.k = 0;

    for(int i=0;i<init.length();i++)
    {
        if(init[i] == '.')
        {
            point = true;
            //nozero = true;
            continue;
        }              
        if(init[i] !='0' && init[i] != '.')
        {
            nozero = true;
        }
        if(nozero == false)
        {
            if(point == true)
            {
                ret.k--;
            }
            continue;
        }

        //ret.d.push_back(init[i]);
        if(ret.d.length() < n)
        {
            ret.d += init[i];
        }
        else if(point == true)
        {
            break;
        }

        if(point == false)
        {
            ret.k++;
        }
    }

    if(nozero == false)
    {
        ret.k = 0;
    }
    //补0
    for(int i=ret.d.length();i<n;i++)
    {
        ret.d += '0';
    }

    return ret;
}

int main()
{
	int n;
	string a,b;
	cin>>n>>a>>b;
	if(b=="0"){while(1){}}
	
	FORM forma,formb;
	forma = formStandard(a,n);
	formb = formStandard(b,n);
	//if(forma.k==0){while(1){}}
    if(forma.d==formb.d && forma.k==formb.k)
    {
        cout<<"YES 0."<<forma.d<<"*10^"<<forma.k<<endl;
    }
    else
    {
        cout<<"NO";
        cout<<" 0."<<forma.d<<"*10^"<<forma.k;
        cout<<" 0."<<formb.d<<"*10^"<<formb.k;
        cout<<endl;
    }

	//system("pause");
	return 0;
}

 

//

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值