PAT 1060

#include<cstdio>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;

int n;
string str1,str2,str3,str4;
string change(string s,int &e)
{
	e=0;
	int k=0;
	int num=0;
	string res;
	while(s.length()>0&&s[0]=='0')
	{
		s.erase(s.begin());
	}
	if(s[0]=='.')
	{
		s.erase(s.begin());
		while(s.length()>0&&s[0]=='0')
		{
			s.erase(s.begin());
			e--;
		}
	}
	else
	{
		while(k<s.length()&&s[k]!='.')
		{
			k++;
			e++;
		}
		if(k<s.length())
			s.erase(s.begin()+k);
	}
	if(s.length()==0)
			e=0;
	k=0;
	
	while(num<n)
	{
		if(k<s.length())
		{
			res=res+s[k++];
		}
		else
			res=res+'0';
		num++;
	}
	return res;
}
int main()
{
	cin>>n>>str1>>str2;
	int e1=0,e2=0;
	str3=change(str1,e1);
	str4=change(str2,e2);
	if(e1==e2&&str3==str4)
	{
		cout<<"YES "<<"0."<<str3<<"*10^"<<e1;
	}
	else
	{
		cout<<"NO "<<"0."<<str3<<"*10^"<<e1<<" 0."<<str4<<"*10^"<<e2;
	}
	system("pause");
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值