-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprog4.c
53 lines (48 loc) · 904 Bytes
/
prog4.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
#include <stdio.h>
#include "inputs/input4"
int increasing(char * s)
{
while (s[1] != '\0') {
if (s[0] > s[1]) {
return 0;
}
s++;
}
return 1;
}
int hasdouble(char *s, int isolated)
{
int ok = 0;
while (s[1] != '\0') {
if (s[0] == s[1]) {
ok = 1;
if (isolated) { // must disqualify if more than two match
if ((s[-1] != s[0] && s[2] != s[0])) {
return 1;
}
ok = 0;
}
}
s++;
}
return ok;
}
int main(int argc, char * argv[])
{
int count1 = 0;
int count2 = 0;
char s[1024] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
char * s2 = &s[4]; // leave a margin before where we store the string
for (int i = START; i <= END; i++) {
sprintf(s2, "%d", i);
if (increasing(s2)) {
if (hasdouble(s2, 0)) count1++;
if (hasdouble(s2, 1)) {
count2++;
}
}
}
printf("Count 1: %d\n", count1);
printf("Count 2: %d\n", count2);
return 0;
}