算法思路:
只需要仔细分析各种情况,分好类别即可。
#include <iostream>
#include <vector>
#include <math.h>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
int n;
string fun(string s,int &k)
{
string ans;
while(s.size()>0&&s[0]=='0'){
s.erase(s.begin());
}
int i=0;
if(s[0]=='.'){
s.erase(s.begin());
while(s.length()>0&&s[0]=='0'){
k--;
s.erase(s.begin());
}
i=0;
if(s.length()==0) k=0;
while(ans.size()<n){
if(i<s.size())
ans=ans+s[i++];
else{
ans+='0';
}
}
return ans;
}else{
i=0;
while(i<s.length()&&s[i]!='.')
{
i++;
k++;
if(s[i]=='.'&&i<s.length()){
s.erase(i);//天哪,我开始写的是s.erase(s[i]),,噗
break;
}
}
i=0;
if(s.length()==0) k=0;
while(ans.length()<n){
if(i<s.size())
ans=ans+s[i++];
else{
ans+='0';
}
}
return ans;
}
}
int main()
{
string s1,s2,s3,s4;
cin >> n >>s1>>s2;
int e1=0,e2=0;
s3=fun(s1,e1);
s4=fun(s2,e2);
if(s3==s4&&e1==e2){
printf("YES ");
cout<<"0."<<s3<<"*10^"<<e1;
}
else{
printf("NO ");
cout<<"0."<<s3<<"*10^"<<e1<<" 0."<<s4<<"*10^"<<e2;
}
}