问题描述
问题分析
刚开始没有HINT
所以想的比较麻烦
超长代码如下:
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
| #include<stdio.h>
#include<string.h>
int main() {
char s[100];
int x,l,i;
int re,t,p;
while(scanf("%s",s)!=EOF) {
l=strlen(s);
for(i=x=re=0; i<l; i++) {
if(i==0) {
if(s[i]=='-') {
i++;
x=1;
}
for(re=0; '0'<=s[i]&&s[i]<='9'; i++) {
re=re*10+s[i]-'0';
}
if(x==1) {
x=0;
re=-re;
}
}
if(s[i]=='+') {
i++;
if(s[i]=='-') {
i++;
x=1;
}
for(p=0; '0'<=s[i]&&s[i]<='9'; i++) {
p=p*10+s[i]-'0';
}
if(x==1) {
x=0;
p=-p;
}
re=re+p;
} else if(s[i]=='-') {
i++;
if(s[i]=='-') {
i++;
x=1;
}
for(p=0; '0'<=s[i]&&s[i]<='9'; i++) {
p=p*10+s[i]-'0';
}
if(x==1) {
x=0;
p=-p;
}
re=re-p;
} else if(s[i]=='*') {
i++;
if(s[i]=='-') {
i++;
x=1;
}
for(p=0; '0'<=s[i]&&s[i]<='9'; i++) {
p=p*10+s[i]-'0';
}
if(x==1) {
x=0;
p=-p;
}
re=re*p;
} else if(s[i]=='/') {
i++;
if(s[i]=='-') {
i++;
x=1;
}
for(p=0; '0'<=s[i]&&s[i]<='9'; i++) {
p=p*10+s[i]-'0';
}
if(x==1) {
x=0;
p=-p;
}
re=re/p;
}
if(s[i]=='=') {
i++;
if(s[i]=='-') {
i++;
x=1;
}
for(p=0; '0'<=s[i]&&s[i]<='9'; i++) {
p=p*10+s[i]-'0';
}
if(x==1)
p=-p;
if(re==p)
printf("YES\n");
else
printf("NO\n");
} else
i--;
}
}
return 0;
}
|
另附 @A_ice 的气死人不偿命代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| #include<stdio.h>
int main()
{
int a,b,d,sum;
char s,w;
while(~scanf("%d%c%d%c%d",&a,&s,&b,&w,&d))
{
if(s=='+')
sum=a+b;
if(s=='-')
sum=a-b;
if(s=='*')
sum=a*b;
if(s=='/')
sum=a/b;
if(sum==d)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
|
看完的感觉就是……
我勒个去……这也行 -.-
题目地址:【杭电】[1773]Lovely simple problem two