这个题目考虑到的情况挺多的感觉。
首先科学记数法0.X 除了0以外X都不为零。
然后输入的数据也是很怪。。需要考虑进去。。
比如 0.001 这样的,小数但是小数点后面不是有效数而是0的。
再比如 00100 这样的,整数但是前面有0的。(被坑死。。。当时怎么都查不出来)
再再比如0 应该记为 0.00……0*10^0..
还有精确位数为4 数字为120这样的 还需要补0.
都考虑到了应该就好了。
补一个case3: 1 0.01 0.009
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstring>
#include <climits>
#include <string>
#include <vector>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int n;
struct node {
string num;
string ans;
int dec;
int fac;
int e;
node(){ans="0.";dec = 0;fac =0;e =0;};
};
node a,b;
string int2str(int n){
if(n == 0)
return "0";
string t;
while(n!=0){
t.push_back('0'+ n%10);
n/=10;
}
t.reserve();
return t;
}
void str_cov(node & n1){
int dec = 0 ,fac = 0 , e = 0;
int c = 0;
if(n1.num == "0"){
while(c<n){
n1.ans.push_back('0');
c++;
}
}
else{
int i = 0;
if(n1.num.size() > 2 && n1.num[0] =='0' && n1.num[1] != '.')
while(n1.num[i] == '0')
i++;
if(n1.num.size() > 2 && n1.num[0] =='0' && n1.num[1] == '.'){//0.0X型的小数
i = 2;
while(n1.num[i] == '0'){
e--;i++;
}
while(c < n ){
if(i < n1.num.size()){
n1.ans.push_back(n1.num[i]);
i++;
}
else//补0
n1.ans.push_back('0');
c++;
}
}
else{
while(i < n1.num.size() && n1.num[i] != '.'){
if(c<n)
n1.ans.push_back(n1.num[i]);
e++;c++;i++;
}
if(i < n1.num.size() && n1.num[i] == '.')
i++;
while(c < n){//小数部分还有
if(i < n1.num.size()){
n1.ans.push_back(n1.num[i]);
i++;
}
else
n1.ans.push_back('0');
c++;
}
}
}
n1.ans += "*10^";
if(e < 0){
n1.ans.push_back('-');
e = -e;
}
n1.ans += int2str(e);
}
int main(){
cin >> n >> a.num >> b.num;
str_cov(a);
str_cov(b);
if(a.ans != b.ans)
cout << "NO " << a.ans << " " << b.ans << endl;
else
cout << "YES " << a.ans << endl;
return 0;
}