-
Notifications
You must be signed in to change notification settings - Fork 0
/
ABSYS.c
83 lines (71 loc) · 1.42 KB
/
ABSYS.c
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
#include <stdio.h>
#include <math.h>
#include <string.h>
int main() {
int test;
scanf("%d", &test);
char str[100];
int flag, i, length, sum=0;
int num1, num2, num3;
int size, posplus, poseq;
while(test!=0) {
flag=0;
sum=0;
//scanf(" %[^\n]s", str);
scanf(" %[^\n]s", str);
length=strlen(str);
//printf("%d\n", length);
for(i=0; i<length; i++) {
if(str[i]=='m')
break;
if(str[i]=='+') {
flag=1;
}
if(str[i]=='=') {
flag=2;
}
}
for(i=0; i<length; i++) {
if(str[i]=='+')
posplus=i;
if(str[i]=='=')
poseq=i;
}
sum=0;
size=0;
if(flag==0 || flag==1) {
size=length-1-poseq-1;
for(i=poseq+2; i<length; i++) {
sum=sum+ ((int)str[i]-48)*pow(10, --size);
}
num3=sum;
}
sum=0;
size=0;
if(flag==0 || flag==2) {
size=poseq-posplus-3;
for(i=posplus+2; i<poseq-1; i++) {
sum=sum+ ((int)str[i]-48)*pow(10, --size);
}
num2=sum;
}
sum=0;
size=0;
if(flag==1 || flag==2) {
size=posplus-1;
for(i=0; i<posplus-1; i++) {
sum=sum+ ((int)str[i]-48)*pow(10, --size);
}
num1=sum;
}
if(flag==0)
printf("%d + %d = %d\n", num3-num2, num2, num3);
if(flag==1)
printf("%d + %d = %d\n", num1, num3-num1, num3);
if(flag==2)
printf("%d + %d = %d\n", num1, num2, num1+num2);
//scanf("%s", str);
test--;
}
return 0;
}