-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1-1.c
More file actions
153 lines (133 loc) · 4.21 KB
/
Copy pathP1-1.c
File metadata and controls
153 lines (133 loc) · 4.21 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* <Alizain Charania>
This program finds George (possibly incognito) in a crowd. */
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int CrowdInts[1024];
int NumInts, Location=0;
int Load_Mem(char *, int *);
if (argc != 2) {
printf("usage: ./P1-1 valuefile\n");
exit(1);
}
NumInts = Load_Mem(argv[1], CrowdInts);
if (NumInts != 1024) {
printf("valuefiles must contain 1024 entries\n");
exit(1);
}
int crowd[4096];
int realNum;
int i = 0;
int k = 0;
int j;
int num;
for (i = 0; i < 4096; i++) {
num = CrowdInts[k];
for (j = 0; j < 3; j++) {
realNum = num & 0xFF;
crowd[i] = realNum;
num << 8;
}
}
//printf("%d", crowd[4095]);
i = 0;
while(i < 4096 && Location == 0) {
if (crowd[i] == 8 || crowd[i] == 3) {
if (crowd[i] == 8) {
j = i + 65;
if (crowd[j] == 1) {
j += 128;
if (crowd[j] == 1) {
j += 128;
if (crowd[j] == 3) {
j += 128;
if (crowd[j] == 5) {
j += 64;
if (crowd[j] == 8) {
j += 192;
if (crowd[j] == 8) {
Location = i + 3;
} else {
i += 11;
}
} else {
i += 11;
}
} else {
i += 11;
}
} else {
i += 11;
}
} else {
i += 11;
}
} else {
i += 11;
}
} else if (crowd[i] == 3) {
j = i + 65;
if (crowd[j] == 1) {
j += 128;
if (crowd[j] == 1) {
j += 127;
if (crowd[j] == 7) {
j += 128;
if (crowd[j] == 2) {
j += 64;
if (crowd[j] == 5) {
j += 192;
if (crowd[j] == 3) {
Location = i + 3;
} else {
i += 11;
}
} else {
i += 11;
}
} else {
i += 11;
}
} else {
i += 11;
}
} else {
i += 11;
}
} else {
i += 11;
}
}
}
else {
i++;
}
}
/* your code goes here. */
printf("The rightmost pixel at the top of George's hat is located at: %4d.\n", Location);
exit(0);
}
/* This routine loads in up to 1024 newline delimited integers from
a named file in the local directory. The values are placed in the
passed integer array. The number of input integers is returned. */
int Load_Mem(char *InputFileName, int IntArray[])
{
int N, Addr, Value, NumVals;
FILE *FP;
FP = fopen(InputFileName, "r");
if (FP == NULL) {
printf("%s could not be opened; check the filename\n", InputFileName);
return 0;
} else {
for (N=0; N < 1024; N++) {
NumVals = fscanf(FP, "%d: %d", &Addr, &Value);
if (NumVals == 2)
IntArray[N] = Value;
else
break;
}
fclose(FP);
return N;
}
}