-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathsolve.c
More file actions
48 lines (48 loc) · 790 Bytes
/
solve.c
File metadata and controls
48 lines (48 loc) · 790 Bytes
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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int compareVersion(char* version1, char* version2) {
char *p = version1;
char *q = version2;
while (*p || *q) {
int d1 = 0;
while (*p && isdigit(*p)) {
d1 *= 10;
d1 += (*p - '0');
p++;
}
int d2 = 0;
while (*q && isdigit(*q)) {
d2 *= 10;
d2 += (*q - '0');
q++;
}
if (d1 > d2)
return 1;
if (d1 < d2)
return -1;
if (*p)
p++;
if (*q)
q++;
}
return 0;
}
int main(int argc, char **argv)
{
char s1[20],s2[20];
while (scanf("%s%s", s1, s2) != EOF) {
switch (compareVersion(s1, s2)) {
case 1:
printf("%s > %s\n", s1, s2);
break;
case -1:
printf("%s < %s\n", s1, s2);
break;
default:
printf("%s == %s\n", s1, s2);
}
}
return 0;
}