-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathA1060.cpp
79 lines (74 loc) · 1.28 KB
/
A1060.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <cstdio>
#include <cstring>
using namespace std;
struct Number{
int digit[110];
int exp, len;
Number() : exp(0), len(0) {
memset(digit, 0, sizeof(digit));
}
} a, b;
Number transfer(char str[]){
Number a;
int len = strlen(str);
bool flag = true;
int i = 0;
while(str[i] == '0' && i < len) ++i;
if(i == len) return a;
if(str[i] == '.'){
++i;
while(str[i] == '0' && i < len){
--a.exp;
++i;
}
if(i == len) a.exp = 0;
else{
while(i < len){
a.digit[a.len++] = str[i++] - '0';
}
}
}else{
while(i < len){
if(str[i] != '.'){
a.digit[a.len++] = str[i] - '0';
if(flag == true)
++a.exp;
}else{
flag = false;
}
++i;
}
}
return a;
}
bool compare(int n, const Number &n1, const Number &n2){
if(n1.exp != n2.exp) return false;
for(int i = 0; i < n; ++i){
if(n1.digit[i] != n2.digit[i]) return false;
}
return true;
}
void print(int n, const Number &num){
printf("0.");
for(int i = 0; i < n; ++i){
printf("%d", num.digit[i]);
}
printf("*10^%d", num.exp);
}
int main(){
int n;
char str1[110], str2[110];
scanf("%d%s%s", &n, str1, str2);
a = transfer(str1);
b = transfer(str2);
if(compare(n, a, b)){
printf("YES ");
print(n, a);
}else{
printf("NO ");
print(n, a);
printf(" ");
print(n, b);
}
return 0;
}