-
Notifications
You must be signed in to change notification settings - Fork 0
/
simplified_test.c
114 lines (106 loc) · 2.25 KB
/
simplified_test.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* simplified_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ramichia <ramichia@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/21 19:10:13 by ramichia #+# #+# */
/* Updated: 2016/12/01 18:13:44 by ramichia ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int testnombredeligne(char *buf)
{
int i;
int z;
int j;
i = 0;
z = 0;
j = 0;
if (buf == NULL)
return (1);
while (buf[i])
{
if (buf[i] != '.' && buf[i] != '#' && buf[i] != '\n')
return (1);
if (buf[i] == '#')
z++;
if (buf[i] == '\n')
j++;
i++;
}
if (z % 4 != 0 || z > 104 || z < 4 || (j - 4) % 5 != 0 \
|| (i - 20) % 21 != 0)
return (1);
return (z);
}
int test_input(char *buf)
{
int i;
int j;
i = 4;
j = 0;
while (buf[i])
{
if (buf[i] != '\n')
return (1);
j++;
if (j == 4 || (j - 4) % 5 == 0)
{
i++;
if (buf[i] != '\n' && buf[i] != '\0' && buf[i + 1] == '\0')
return (1);
}
else
i = i + 5;
}
return (0);
}
int checkeachblock(char *str, int i)
{
if (str[i + 1] == '#')
return (0);
else if (str[i - 1] == '#')
return (0);
else if (str[i + 5] == '#')
return (0);
else if (str[i - 5] == '#')
return (0);
else if (str[i + 6] == '#')
return (0);
else if (str[i - 6] == '#')
return (0);
else if (str[i + 4] == '#')
return (0);
else if (str[i - 4] == '#')
return (0);
else
return (1);
}
int simplified_test(char *str)
{
int i;
int r;
int count;
i = 0;
while (str[i])
{
r = 0;
count = 0;
while (r < 21)
{
if (str[i] == '#')
{
if (checkeachblock(str, i) != 0)
return (1);
count++;
}
i++;
r++;
}
if (count != 4)
return (1);
}
return (0);
}