-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathP1553.cpp
44 lines (41 loc) · 1.07 KB
/
P1553.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
#include <bits/stdc++.h>
#define MAXN 100
using namespace std;
typedef unsigned long long ULL;
ULL a, b;
char c;
string line;
string reverse(ULL n)
{
string s = "";
while (n)
{
s += (n%10+'0');
n /= 10;
}
return s;
}
int main()
{
cin >> line;
if (line.find_first_of('.') == string::npos &&
line.find_first_of('/') == string::npos &&
line.length() >= 19) // 处理大于等于 19 位的数字
{
if (line[line.length() - 1] == '%') reverse(line.begin(), line.end()-1);
else reverse(line.begin(), line.end());
int i = line.find_first_not_of('0');
for (; i < line.length(); i++) printf("%c", line[i]);
}
else // 只要数字小于 19 位,均可由以下语句处理
{
sscanf(line.c_str(), "%lld%c%lld", &a, &c, &b);
string s1 = reverse(a), s2 = reverse(b);
sscanf(s1.c_str(), "%lld", &a);
sscanf(s2.c_str(), "%lld", &b);
printf("%lld%c", a, c);
if (b) printf("%lld", b);
if (c == '.' && b == 0) printf("0");
}
return 0;
}