-
Notifications
You must be signed in to change notification settings - Fork 1
/
sosuu.c
247 lines (214 loc) · 6.13 KB
/
sosuu.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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#define EXTIO_SCAN_ASCII (*(volatile unsigned int *)0x0310)
#define EXTIO_SCAN_REQ (*(volatile unsigned int *)0x030c)
#define EXTIO_SCAN_STROKE (*(volatile unsigned int *)0x0308)
#define SCAN_STRORING (unsigned int)0xffffffff
#define EXTIO_PRINT_STROKE (*(volatile unsigned int *) 0x0300)
#define EXTIO_PRINT_ASCII (*(volatile unsigned int *) 0x0304)
#define TRUE 0x1
#define FALSE 0x0
unsigned int sosuu_check(unsigned int kouho);
unsigned int my_a2i();
void my_i2a();
void my_print();
void my_scan();
main() {
unsigned int i;
unsigned int k;
unsigned int str1[16];
unsigned int str2[16];
/* "HELLO" $B$r(B print */
str1[0] = 'H'; str1[1] = 'E';
str1[2] = 'L'; str1[3] = 'L';
str1[4] = 'O'; str1[5] = '\n';
str1[6] = '\0';
my_print(str1);
while (1) {
/* "NUM=" $B$r(B print */
str1[0] = 'N'; str1[1] = 'U';
str1[2] = 'M'; str1[3] = '=';
str1[4] = '\0';
my_print(str1);
/* $B%-!<%\!<%I$+$iF~NO$5$l$?J8;zNs!J?t;z!K$r(B str2[] $B$K5-21(B */
my_scan(str2);
/* "ECHO " $B$r(B print */
str1[0] = 'E'; str1[1] = 'C';
str1[2] = 'H'; str1[3] = 'O';
str1[4] = ' '; str1[5] = '\0';
my_print(str1);
/* str2[] $B$r(B print */
my_print(str2);
/* '\n' $B$r(B print */
str1[0] = '\n'; str1[1] = '\0';
my_print(str1);
/* $BJ8;zNs!J?t;z!K(B srt2[] $B$r(B unsigned int $B$KJQ49(B */
k = my_a2i(str2);
for (i = 3; i <= k; i++) {
/* $BAG?tH=Dj(B */
if ( sosuu_check(i) ) {
/* unsigned int i $B$rJ8;zNs!J?t;z!K$KJQ49$7$F(B print */
my_i2a(i);
}
}
/* '\n' $B$r(B print */
str1[0] = '\n'; str1[1] = '\0';
my_print(str1);
}
}
/* unsigned int kouho $B$NAG?tH=Dj$r9T$&4X?t(B */
/* $BAG?t$J$i(B TRUE $B$rJV$9(B */
/* $BAG?t$G$J$$$J$i(B FALSE $B$rJV$9(B */
unsigned int sosuu_check(unsigned int kouho) {
unsigned int t, tester, result;
if ((kouho % 2) == 0) {
/* kouho $B$O6v?t$G$"$k(B == TRUE */
return FALSE;
} else {
result = TRUE;
for (tester = 3; tester < kouho/2; tester += 2) {
/* kouho $B$,K\Ev$KAG?t$+$I$&$+$r%A%'%C%/(B */
if ((kouho % tester) == 0) {
/* kouho $B$O(B tester $B$NG\?t$G$"$k(B */
result = FALSE;
}
}
return result;
}
}
/* $BJ8;zNs!J?t;z!K(B srt[] $B$r(B unsigned int $B$KJQ49$9$k4X?t(B */
/* unsigned int result $B$rJV$9(B */
unsigned int my_a2i(str)
unsigned int *str;
{
unsigned int *str_tmp;
unsigned int k;
unsigned int result;
str_tmp = str;
for (k = 0; *str_tmp != '\0'; k++) {
str_tmp++;
}
result = 0;
str_tmp = str;
if (k == 1) {
result = *str_tmp - '0';
} else if (k == 2) {
for (k = 0; k < (*str_tmp - '0'); k++) {
result = result + 10;
}
str_tmp++;
result = result + (*str_tmp - '0');
} else if (k == 3) {
for (k = 0; k < (*str_tmp - '0'); k++) {
result = result + 100;
}
str_tmp++;
for (k = 0; k < (*str_tmp - '0'); k++) {
result = result + 10;
}
str_tmp++;
result = result + (*str_tmp - '0');
}
return result;
}
/* unsigned int i $B$rJ8;zNs!J?t;z!K$KJQ49$7$F(B print $B$9$k4X?t(B */
void my_i2a(unsigned int i) {
unsigned int counter;
unsigned int s[4];
for (counter = 0; i >= 10; counter++) {
i -= 10;
}
s[0] = counter + '0';
s[1] = i + '0';
s[2] = ' ';
s[3] = '\0';
my_print(s);
}
/* $B%-!<%\!<%I$+$iF~NO$5$l$?J8;zNs$r(B str[] $B$K5-21$9$k4X?t(B */
void my_scan(str)
unsigned int *str;
{
EXTIO_SCAN_STROKE = (unsigned int)0x00000000;
EXTIO_SCAN_REQ = (unsigned int)0x00000001;
EXTIO_SCAN_STROKE = (unsigned int)0x00000001;
EXTIO_SCAN_STROKE = (unsigned int)0x00000000;
EXTIO_SCAN_STROKE = (unsigned int)0x00000001;
while (EXTIO_SCAN_ASCII == SCAN_STRORING) {
EXTIO_SCAN_STROKE = (unsigned int)0x00000000;
EXTIO_SCAN_STROKE = (unsigned int)0x00000001;
}
while ((*str = EXTIO_SCAN_ASCII) != (unsigned int)0x3e) { // 0x3e=RETURN
if ((*str >= 1) && (*str <= 26)) {
*str = 'A' + *str - 1;
} else if ((*str >= 48) && (*str <= 57)) {
*str = '0' + *str - 48;
} else {
if (*str == 0) {
*str = '@';
} else if (*str == 27) {
*str = '[';
} else if (*str == 29) {
*str = ']';
} else if ((*str >= 32) && (*str <= 47)) {
*str = ' ' + *str - 32;
} else if (*str == 58) {
*str = '?';
} else if (*str == 59) {
*str = '=';
} else if (*str == 60) {
*str = ';';
} else if (*str == 61) {
*str = ':';
} else if (*str == 62) {
*str = '\n';
} else {
*str = '@';
}
}
EXTIO_SCAN_STROKE = (unsigned int)0x00000000;
EXTIO_SCAN_STROKE = (unsigned int)0x00000001;
str++;
}
*str = '\0';
EXTIO_SCAN_STROKE = (unsigned int)0x00000000;
EXTIO_SCAN_REQ = (unsigned int)0x00000000;
EXTIO_SCAN_STROKE = (unsigned int)0x00000001;
EXTIO_SCAN_STROKE = (unsigned int)0x00000000;
}
/* $BJ8;zNs(B str[] $B$rI=<($9$k4X?t(B */
void my_print(str)
unsigned int *str;
{
while (*str != '\0') {
EXTIO_PRINT_STROKE = (unsigned int)0x00000000;
if ((*str >= 'A') && (*str <= 'Z')) {
EXTIO_PRINT_ASCII = *str - 'A' + 1;
} else if ((*str >= 'a') && (*str <= 'z')) {
EXTIO_PRINT_ASCII = *str - 'a' + 1;
} else if ((*str >= '0') && (*str <= '9')) {
EXTIO_PRINT_ASCII = *str - '0' + 48;
} else {
if (*str == '@') {
EXTIO_PRINT_ASCII = (unsigned int)0;
} else if (*str == '[') {
EXTIO_PRINT_ASCII = (unsigned int)27;
} else if (*str == ']') {
EXTIO_PRINT_ASCII = (unsigned int)29;
} else if ((*str >= ' ') && (*str <= '/')) {
EXTIO_PRINT_ASCII = *str - ' ' + 32;
} else if (*str == '?') {
EXTIO_PRINT_ASCII = (unsigned int)58;
} else if (*str == '=') {
EXTIO_PRINT_ASCII = (unsigned int)59;
} else if (*str == ';') {
EXTIO_PRINT_ASCII = (unsigned int)60;
} else if (*str == ':') {
EXTIO_PRINT_ASCII = (unsigned int)61;
} else if (*str == '\n') {
EXTIO_PRINT_ASCII = (unsigned int)62;
} else {
EXTIO_PRINT_ASCII = (unsigned int)0x00000000;
}
}
EXTIO_PRINT_STROKE = (unsigned int)0x00000001;
str++;
}
}