-
Notifications
You must be signed in to change notification settings - Fork 0
/
A1060-1.cpp
58 lines (53 loc) · 1.07 KB
/
A1060-1.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
/*
* author: zhouyuhao
* created: 2024-05-04 09:17:00
* modified: 2024-05-04 09:30:00
* item: Programming Ability Test
* site: 914, Harbin
*/
#include <iostream>
using namespace std;
string trans(string s, int n) {
while (s[0] == '0' && s.size() > 1 && s[1] != '.') {
s.erase(0, 1);
}
int dot = -1, nonZero = -1;
for (int i = 0; i < (int)s.size() && (dot == -1 || nonZero == -1); i++) {
if (s[i] == '.') {
dot = i;
} else if (nonZero == -1 && s[i] != '0') {
nonZero = i;
}
}
string num;
int e = 0;
if (nonZero != -1) {
if (nonZero == 0) {
if (dot != -1) {
s.erase(dot, 1);
e = dot;
} else {
e = s.size();
}
} else {
e = dot - nonZero + 1;
}
num = s.substr(nonZero, n);
}
if ((int)num.size() < n) {
num.append(n - num.size(), '0');
}
return "0." + num + "*10^" + to_string(e);
}
int main(int argc, char const *argv[]) {
int n;
string a, b;
cin >> n >> a >> b;
string sa = trans(a, n), sb = trans(b, n);
if (sa == sb) {
cout << "YES " << sa << "\n";
} else {
cout << "NO " << sa << " " << sb << "\n";
}
return 0;
}