主要还是简化思想吧,找最近的有效数字的位置和小数点位置,然后这两部分都有细节补全.
#include<bits/stdc++.h>
using namespace std;#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=1e2+10;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){if(y==0) return x;return gcd(y,x%y);
}
int n,pos1,pos2;
string s,t;
string tmps,tmpt;
string solve(string s,int n,int &p){string ret="";int p1,p2,len=s.size(),i=0;while(i<len&&(s[i]=='.'||s[i]=='0')) i++;p1=i;if(i==len) rep(i,0,n) ret+='0';else{for(int j=i,k=0;j<len&&k<n;j++,k++){if(s[j]=='.') k--;else ret+=s[j];}int tmp=ret.size();for(int j=tmp+1;j<=n;j++) ret+='0';}i=0;while(i<len&&s[i]!='.') i++;p=i-p1;if(p<0) p++;if(ret[0]=='0') p=0;return ret;
}
int main(){ios::sync_with_stdio(false);cin>>n>>s>>t;tmps=solve(s,n,pos1);tmpt=solve(t,n,pos2);if(tmps==tmpt&&pos1==pos2){cout<<"YES ";cout<<"0."<<tmps<<"*10^"<<pos1<<"\n";}else{cout<<"NO ";cout<<"0."<<tmps<<"*10^"<<pos1<<" ";cout<<"0."<<tmpt<<"*10^"<<pos2<<"\n";}return 0;
}