考虑:
1、0001.222
2、0.0123
3、0
4、不足位数0补齐
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<stack>
#include<queue>
using namespace std;
int n;
string changes(string s){
string a;
int i = 0;
int j = 0;
int flag = 0;
if(s[0] == '0' && s[1] == '.'){
j += 2;
while(j < s.size() && i < n){
if(s[j] == '0' && flag == 1){
a.push_back(s[j]);
i++;
}
else if(s[j] != '0'){
a.push_back(s[j]);
i++;
flag = 1;
}
j++;
}
}
else if(s.size() == 1 && s[0] == '0'){
for(int i = 0; i < n; i++){
a.push_back('0');
}
}
else{
while(j < s.size() && i < n){
if(s[j] == '0' && flag == 1){
a.push_back(s[j]);
i++;
}
else if(s[j] != '0' && s[j] != '.'){
a.push_back(s[j]);
flag = 1;
i++;
}
j++;
}
}
while(a.size() < n){//不足补零
a.push_back('0');
}
return a;
}
int getlength(string s){
int i = 0;
int j = 0;
int flag = 0;
if(s[0] == '0' && s[1] == '.'){
j += 2;
while(j < s.size() && s[j] == '0'){
i--;
j++;
};
}
else if(s.size() == 1 && s[0] == '0'){
i = 0;
}
else{
while(j < s.size() && s[j] != '.'){
if(s[j] == '0'){
if(flag != 0){
i++;
}
}
else{
i++;
flag = 1;
}
j++;
}
}
return i;
}
int main(){
string s1, s2;
cin>>n>>s1>>s2;
string ts1 = changes(s1);
string ts2 = changes(s2);
int e1, e2;
e1 = getlength(s1);
e2 = getlength(s2);
if(ts1 == ts2 && e1 == e2){
printf("YES 0.%s*10^%d",ts1.c_str(),e1);
}
else{
printf("NO 0.%s*10^%d 0.%s*10^%d",ts1.c_str(),e1,ts2.c_str(),e2);
}
return 0;
}