-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP1022.cpp
76 lines (69 loc) · 1.32 KB
/
P1022.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
#include<stdio.h>
char x;
long long cur, k, b,opp;
int main()
{
char s;
s = getchar();
bool valueget = false;
opp = 1;
k = 0;
b = 0;
cur = 0;
long long value=0;
int sign = 1;
while(true)
{
if(s>='a'&&s<='z')
{
x = s;
if(cur==0&&valueget==false)
{
k = 1;
}
else
{
k = k + value * opp * sign;
value = 0;
sign = 1;
}
}
else if(s>='0'&&s<='9')
{
value = value * 10 + s - '0';
}
else if(s=='-')
{
b = b + value * opp * sign;
value = 0;
sign = -1;
}
else if(s=='+')
{
b = b + value * opp * sign;
value = 0;
sign = 1;
}
else if(s=='=')
{
b = b + value * opp * sign;
value = 0;
sign = 1;
opp = -1;
}
else
{
b = b + value * opp * sign;
break;
}
cur++;
s = getchar();
}
double ss = (double)k;
double t = (double)b;
double ans = (double)(-1 * t / ss);
if(ans==0)
ans = 0;
printf("%c=%0.3f", x, ans);
return 0;
}