-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathII.cpp
105 lines (93 loc) · 1.48 KB
/
II.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#define endl '\n'
using namespace std;
const int MAXN = 105;
char str[MAXN];
int main()
{
while(scanf("%s",str) == 1)
{
int i = 0,mark1 = -1,mark2,f1,f2,f3;
f1 = 1,f2 = 1,f3 = 1;
while((str[i] > '9' || str[i] <= '0'))
{
if(str[i] == '-')
{
i++;
continue;
}
if(str[i] == '.')
{
mark1 = i;
break;
}
if(str[i] == 'e')
{
mark2 = i;
break;
}
str[i] = -1;
i++;
}
if(str[i] <= '9' && str[i] > '0')
{
f3 = 0;
}
while(str[i] != 'e')
{
if(str[i] == '.')mark1 = i;
i++;
}
mark2 = i;
//cout << str[mark2] << endl;
//cout << mark1 << endl;
int j;
for(j = i - 1;j > mark1 && mark1 != -1;j--)
{
if(str[j] > '0' && str[j] <= '9')
{
f2 = 0;
break;
}
str[j] = -1;
}
if(f2 && !f3)str[mark1] = -1;
int l = strlen(str) - 1;
for(i = mark2 + 1;str[i];i++)
{
if(str[i] == '+')
{
str[i] = -1;
continue;
}
if(str[i] == '0' && f1)
{
str[i] = -1;
continue;
}
if(str[i] > '0' && str[i] <= '9')
{
f1 = 0;
break;
}
}
int f4 = 0,f5 = 1;
//cout << f3 << endl;
if(f3)cout << 0;
for(i = 0;str[i];i++)
{
if(str[i] == -1)continue;
if(str[i] == '.')f4 = 1;
if(f4 && str[i] >= '0' && str[i] <= '9')f5 = 0;
if(str[i] == 'e' && f4 && f5)cout << 0;
cout << str[i];
}
if(f1)cout << 0;
cout << '\n';
}
return 0;
}