地址:https://pintia.cn/problem-sets/994805342720868352/problems/994805413520719872
最烦做模拟题:
此题的坑很多:
1>有前导0
2>0输出也要0.00…0 *10^0
3>小数点后有好多0
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int inf = 0x3f3f3f3f;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int n;
pair<string,int> zhuan(string s)
{
int k = 0;
//去掉前导0
while(s.size() > 0 && s[0] == '0'){
s.erase(s.begin());
}
//cout << s << endl;
int cnt = 0;
if(s[0] == '.'){
s.erase(s.begin());
while(s.size() > 0 && s[0] == '0'){
s.erase(s.begin());
cnt--;
}
}else{
while(k < s.size() && s[k] != '.'){
k++;
cnt++;
}
if(k < s.size()){
s.erase(s.begin() + k);
}
}
//cout << s << " " << cnt << endl;
if(s.size() == 0) cnt = 0;
int num = 0;
k = 0;
string ans = "0.";
while(num < n){
if(k < s.size()) ans += s[k++];
else ans += '0';
num++;
}
return mp(ans,cnt);
}
int main()
{
string s1,s2;
cin >> n >> s1 >> s2;
pair<string,int>ans1 = zhuan(s1);
pair<string,int>ans2 = zhuan(s2);
if(ans1.fi == ans2.fi && ans1.se == ans2.se){
printf("YES %s*10^%d\n",ans1.fi.c_str(),ans1.se);
}else{
printf("NO %s*10^%d %s*10^%d\n",ans1.fi.c_str(),ans1.se,ans2.fi.c_str(),ans2.se);
}
return 0;
}