是我太菜,这题做的好麻烦,标注里的案例挨个试
#include<iostream>
#include<string>
using namespace std;
int n;
string init(string a,int &s)
{
int i=0;
int l=0;
int len=a.length();
while(i<len&&a[0]=='0')
//因while(i<a.length()&&a[i]=='0')出现错误
{
a.erase(a.begin());
//因写成a.erase(a.begin()+i);出现错误
i++;
}
if(i<len&&a[0]=='.')
{
a.erase(a.begin());
i++;
while(i<len&&a[0]=='0')
{
a.erase(a.begin());
i++;
s--;
}
if(i>=len)
s=0;
}
else
{
i=0;
while(i<a.length()&&a[i]!='.')
{l++;i++;}
s=l;
if(i<a.length()&&a[i]=='.')
a.erase(a.begin()+i);
// cout<<a.length()<<endl;
}
while(a.length()<n)
{
a+="0";
}
return a.substr(0,n);
}
int main()
{
string a,b;
string stra,strb;
while(cin>>n)
{
cin>>a>>b;
int as=0,bs=0;
stra=init(a,as);
strb=init(b,bs);
if(stra[0]=='0'&&strb[0]=='0')
{
as=as<bs?as:bs;
cout<<"YES 0."<<stra<<"*10^"<<as<<endl;
continue;
}
if(stra==strb&&as==bs)
cout<<"YES 0."<<stra<<"*10^"<<as<<endl;
else
cout<<"NO 0."<<stra<<"*10^"<<as<<" 0."<<strb<<"*10^"<<bs<<endl;
}
return 0;
}
/*
4 0000 0000.00
4 00123.5678 0001235
3 0.0520 0.0521
4 00000.000000123 0.0000001230
4 00100.00000012 100.00000013
5 0010.013 10.012
4 123.5678 123.5
3 123.5678 123
4 123.0678 123
3 0.000 0
12 123456789012345 123456789012300
12 123456789012345 123456789010000
*/