因为不常用string,于是尝试用char数组解题,由于无法erase,于是需要定位操作,我感觉写出来十分麻烦,看的也不舒服,但是既然写了还是po出来吧,以后要练习多用string啊。
int n;
char num1[110] = {0}, num2[110] = {0}, num1_temp[110] = {0}, num2_temp[110] = {0};
int smallZero(char a[], int pos, int t){
char num_temp[110] = {0};
int b = 0;
while(a[pos] == '0') {b++;pos++;}
if(a[pos] == '\0') b = 0;
num_temp[0] = '0'; num_temp[1] = '.';
bool flag = false;
for(int i = 2; i<=n+1; i++){
if(flag || a[pos] == '\0') {
num_temp[i] = '0';
flag = true;
continue;
}
num_temp[i] = a[pos++];
}
num_temp[n+2] = '\0';
if(t == 1) strcpy(num1_temp, num_temp);
else strcpy(num2_temp, num_temp);
return -b;
}
int largeZero(char a[], int pos, int t){
char num_temp[110] = {0};
int pos_temp = pos;
int b = 0;
int len = (int)strlen(a);
while(pos < len){
if(a[pos++] != '.') {b++;}
else break;
}
num_temp[0] = '0'; num_temp[1] = '.';
bool flag = false;
for(int i = 2; i<=n+1; i++){
if(flag || a[pos_temp] == '\0') {
num_temp[i] = '0';
flag = true;
continue;
}
if(a[pos_temp] == '.') pos_temp++;
num_temp[i] = a[pos_temp++];
}
num_temp[n+2] = '\0';
if(t == 1) strcpy(num1_temp, num_temp);
else strcpy(num2_temp, num_temp);
return b;
}
int main(){
scanf("%d %s %s", &n, num1, num2);
int i1 = 0;
while(num1[i1] == '0') i1++;
int b1, b2;
if(num1[i1] == '.') b1 = smallZero(num1, i1+1, 1);
else b1 = largeZero(num1, i1, 1);
int i2 = 0;
while(num2[i2] == '0') i2++;
if(num2[i2] == '.') b2 = smallZero(num2, i2+1, 2);
else b2 = largeZero(num2, i2, 2);
if(strcmp(num1_temp, num2_temp) == 0 && b1 == b2){
printf("YES %s*10^%d\n", num1_temp, b1);
}
else{
printf("NO %s*10^%d %s*10^%d", num1_temp, b1, num2_temp, b2);
}
}