输入为0.0000xxxx的数字,xxx.xxx的也考虑了
但是还有2个点没过
#include <cstdio>
#include <string>
#include <string.h>
using namespace std;
#define MAX 100010
int n;
//k:c中保存了几位数,
//i:a中读到字符串中的几位数
//cnt
int f(char a[],char c[]){
int k=0;
int cnt=0;
int ans=0;
if(a[0]=='0'){
if(a[1]=='.'){
int i=2;
while(a[i]=='0'){
cnt++;
i++;
}
for(;i<strlen(a);i++){
if(k<n){
c[k++]=a[i];
}
}
c[k]='\0';
return -cnt;
}else{
c="0";
return 0;
}
}else{
for(int i=0;i<strlen(a);i++){
if(k<n){
if(a[i]=='.'){
ans=cnt;
}else{
c[k++]=a[i];
cnt++;
}
}else{
if(a[i]=='.'){
break;
}else{
cnt++;
}
}
}
while(k<n){
c[k++]='0';
}
c[k]='\0';
if(ans!=0){
return ans;
}else{
return cnt;
}
}
}
int main(){
freopen("in.txt","r",stdin);
char a[MAX],b[MAX],c[MAX],d[MAX];
while( scanf("%d %s %s",&n,a,b)!=EOF){
int x=f(a,c);
int y=f(b,d);
if(x==y && strcmp(c,d)==0){
printf("YES 0.%s*10^%d\n",c,x);
}else{
printf("NO 0.%s*10^%d 0.%s*10^%d\n",c,x,d,y);
}
}
return 0;
}