0325
This commit is contained in:
parent
0bee7379cc
commit
ffc6eea779
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
||||
*.exe
|
||||
.idea
|
||||
cmake*
|
5
.vscode/c.code-snippets
vendored
5
.vscode/c.code-snippets
vendored
@ -81,11 +81,6 @@
|
||||
"body": ["#define min(i, j) (((i) < (j)) ? (i) : (j))"],
|
||||
"description": "Define function min"
|
||||
},
|
||||
"Fake loop": {
|
||||
"prefix": "fake_loop",
|
||||
"body": ["while (0) { /* Fake loop */", "}"],
|
||||
"description": "Fake loop"
|
||||
},
|
||||
"Define Boolean": {
|
||||
"prefix": "define_boolean",
|
||||
"body": ["#define bool int", "#define true 1", "#define false 0"],
|
||||
|
12
.vscode/c.fake.code-snippets
vendored
Normal file
12
.vscode/c.fake.code-snippets
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"Fake loop": {
|
||||
"prefix": "fake_loop",
|
||||
"body": ["while (0) { /* Fake loop */", "}"],
|
||||
"description": "Fake loop"
|
||||
},
|
||||
"Fake array": {
|
||||
"prefix": "fake_array",
|
||||
"body": ["if (0) { /* Fake array */", " int a[1];", "}"],
|
||||
"description": "Fake array"
|
||||
}
|
||||
}
|
51
.vscode/c.template.code-snippets
vendored
Normal file
51
.vscode/c.template.code-snippets
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
{
|
||||
"Define template": {
|
||||
"prefix": "define_template",
|
||||
"body": [
|
||||
"#define _template_func_def(T, func) T_DEFINE_##func(T)",
|
||||
"#define _template_func(T, func) T_##func##__##T"
|
||||
],
|
||||
"description": "Define template"
|
||||
},
|
||||
"Define sort": {
|
||||
"prefix": "define_sort",
|
||||
"body": [
|
||||
"#define SORT_PREDICATE(type, name) bool name(type a, type b)",
|
||||
"#define SORT_SWAP(type, a, b) \\",
|
||||
" { \\",
|
||||
" const type _BLOCK_T = a; \\",
|
||||
" a = b; \\",
|
||||
" b = _BLOCK_T; \\",
|
||||
" }",
|
||||
"",
|
||||
"#define T_DEFINE_less(T) \\",
|
||||
" SORT_PREDICATE(T, T_less__##T) { return a < b; }",
|
||||
"#define T_DEFINE_greater(T) \\",
|
||||
" SORT_PREDICATE(T, T_greater__##T) { return a > b; }",
|
||||
"",
|
||||
"#define T_DEFINE_sort(T) \\",
|
||||
" void T_sort__##T(T *start, const T *end, bool (*predicate)(T, T)) { \\",
|
||||
" T *i, *j; \\",
|
||||
" for (i = start; i < end; i++) { \\",
|
||||
" for (j = i; j < end; j++) { \\",
|
||||
" if (predicate(*i, *j)) { \\",
|
||||
" SORT_SWAP(T, *i, *j); \\",
|
||||
" } \\",
|
||||
" } \\",
|
||||
" } \\",
|
||||
" }",
|
||||
"",
|
||||
"#define T_DEFINE_sort_default(T) \\",
|
||||
" void T_sort_default__##T(T *start, const T *end) { \\",
|
||||
" T_sort__##T(start, end, _template_func(T, less)); \\",
|
||||
" }",
|
||||
"",
|
||||
"#define T_DEFINE_sort_init(T) \\",
|
||||
" _template_func_def(T, less); \\",
|
||||
" _template_func_def(T, greater); \\",
|
||||
" _template_func_def(T, sort); \\",
|
||||
" _template_func_def(T, sort_default);"
|
||||
],
|
||||
"description": "Define sort"
|
||||
}
|
||||
}
|
31
0325/1.c
Normal file
31
0325/1.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#define for_i(i, range, inner) \
|
||||
{ \
|
||||
int i; \
|
||||
for (i = 0; i < range; i++) \
|
||||
inner; \
|
||||
}
|
||||
#define N 12
|
||||
|
||||
int sum(int a[], int n) {
|
||||
int s = 0;
|
||||
int i = n;
|
||||
for (; i < n + 5; i++) {
|
||||
s += a[i % N];
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int a[12], max_sum = 0, max_i = 0;
|
||||
for_i(i, N, scanf("%d", &a[i]));
|
||||
for_i(i, N, {
|
||||
int s = sum(a, i);
|
||||
if (s > max_sum) {
|
||||
max_sum = s;
|
||||
max_i = i;
|
||||
}
|
||||
});
|
||||
printf("%d\n", max_i + 1);
|
||||
return 0;
|
||||
}
|
16
0325/2.c
Normal file
16
0325/2.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#define for_i(i, range, inner) \
|
||||
{ \
|
||||
int i; \
|
||||
for (i = 0; i < range; i++) \
|
||||
inner; \
|
||||
}
|
||||
|
||||
int main() {
|
||||
int a[10], height, count = 0;
|
||||
for_i(i, 10, scanf("%d", &a[i]));
|
||||
scanf("%d", &height);
|
||||
for_i(i, 10, if (a[i] <= height + 30) count++);
|
||||
printf("%d", count);
|
||||
return 0;
|
||||
}
|
33
0325/3.c
Normal file
33
0325/3.c
Normal file
@ -0,0 +1,33 @@
|
||||
#include <stdio.h>
|
||||
#define bool int
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
int main() {
|
||||
int n = 0, length = 0;
|
||||
bool in_word = false;
|
||||
char c;
|
||||
while ((c = getchar()) != '\n') {
|
||||
if (c == ' ') {
|
||||
if (in_word) {
|
||||
in_word = false;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
if (!in_word) {
|
||||
in_word = true;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
length++;
|
||||
}
|
||||
if (n) {
|
||||
printf("%.2f", (float)length / n);
|
||||
} else {
|
||||
printf("0.00");
|
||||
}
|
||||
if (0) { /* Fake array */
|
||||
int a[1];
|
||||
}
|
||||
return 0;
|
||||
}
|
54
0325/4.c
Normal file
54
0325/4.c
Normal file
@ -0,0 +1,54 @@
|
||||
#include <stdio.h>
|
||||
#define for_i(i, range, inner) \
|
||||
{ \
|
||||
int i; \
|
||||
for (i = 0; i < range; i++) \
|
||||
inner; \
|
||||
}
|
||||
#define putbool(x) (printf("%s\n", (x) ? "yes" : "no"))
|
||||
#define bool int
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
scanf("%d\n", &n);
|
||||
for_i(i, n, {
|
||||
char a[1000];
|
||||
int p = -1;
|
||||
char c;
|
||||
bool flag = 1;
|
||||
while ((c = getchar()) != '\n') {
|
||||
if (!flag) {
|
||||
continue;
|
||||
}
|
||||
switch (c) {
|
||||
case '(':
|
||||
case '[':
|
||||
a[++p] = c;
|
||||
break;
|
||||
case ')':
|
||||
case ']':
|
||||
if (p < 0) {
|
||||
putbool(false);
|
||||
flag = 0;
|
||||
break;
|
||||
}
|
||||
if (c == ')' && a[p] == '(' || c == ']' && a[p] == '[') {
|
||||
p--;
|
||||
} else {
|
||||
putbool(false);
|
||||
flag = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
putbool(p < 0);
|
||||
}
|
||||
});
|
||||
return 0;
|
||||
}
|
27
0325/5.c
Normal file
27
0325/5.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
#define for_i(i, range, inner) \
|
||||
{ \
|
||||
int i; \
|
||||
for (i = 0; i < range; i++) \
|
||||
inner; \
|
||||
}
|
||||
#define for_wrapper(a, b, c, d) \
|
||||
{ \
|
||||
a; \
|
||||
for (; b; c) \
|
||||
d; \
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n, a[1000] = {0};
|
||||
int sum = 0;
|
||||
scanf("%d", &n);
|
||||
for_wrapper(int i = 1, i <= n, i++, {
|
||||
for_wrapper(int j = i - 1, j < n, j += i, {
|
||||
a[j] = !a[j];
|
||||
});
|
||||
});
|
||||
for_i(i, n, sum += a[i]);
|
||||
printf("%d", sum);
|
||||
return 0;
|
||||
}
|
21
0325/6.c
Normal file
21
0325/6.c
Normal file
@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
#define bool int
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
int main() {
|
||||
char c;
|
||||
bool is_odd;
|
||||
while ((c = getchar()) != '\n') {
|
||||
if (c == '1') {
|
||||
is_odd = true;
|
||||
} else {
|
||||
is_odd = false;
|
||||
}
|
||||
}
|
||||
printf("%s", is_odd ? "ODD" : "EVEN");
|
||||
if (0) { /* Fake array */
|
||||
int a[1];
|
||||
}
|
||||
return 0;
|
||||
}
|
30
0325/7.c
Normal file
30
0325/7.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
#define bool int
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
#define case_do(c, to) \
|
||||
case c: \
|
||||
printf(to); \
|
||||
break;
|
||||
|
||||
int main() {
|
||||
char c;
|
||||
while ((c = getchar()) != '\n') {
|
||||
switch (c) {
|
||||
case_do('O', "0");
|
||||
case_do('l', "1");
|
||||
case_do('Z', "2");
|
||||
case_do('S', "5");
|
||||
case_do('b', "6");
|
||||
case_do('B', "8");
|
||||
case_do('q', "9");
|
||||
default:
|
||||
printf("%c", c);
|
||||
}
|
||||
}
|
||||
if (0) { /* Fake array */
|
||||
int a[1];
|
||||
}
|
||||
return 0;
|
||||
}
|
34
0325/8.c
Normal file
34
0325/8.c
Normal file
@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
#define for_i(i, range, inner) \
|
||||
{ \
|
||||
int i; \
|
||||
for (i = 0; i < range; i++) \
|
||||
inner; \
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n, a[101] = {0};
|
||||
int max = 0;
|
||||
int out[101];
|
||||
int p = 0;
|
||||
scanf("%d", &n);
|
||||
for_i(i, n, {
|
||||
int x;
|
||||
scanf("%d", &x);
|
||||
a[x]++;
|
||||
});
|
||||
|
||||
for_i(i, 101, {
|
||||
if (a[i] > max) {
|
||||
max = a[i];
|
||||
p = 0;
|
||||
out[p++] = i;
|
||||
} else if (a[i] == max) {
|
||||
out[p++] = i;
|
||||
}
|
||||
});
|
||||
|
||||
for_i(i, p, { printf("%d ", out[i]); });
|
||||
|
||||
return 0;
|
||||
}
|
62
0325/9.c
Normal file
62
0325/9.c
Normal file
@ -0,0 +1,62 @@
|
||||
#define bool int
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
#define _template_func_def(T, func) T_DEFINE_##func(T)
|
||||
#define _template_func(T, func) T_##func##__##T
|
||||
|
||||
#define SORT_PREDICATE(type, name) bool name(type a, type b)
|
||||
#define SORT_SWAP(type, a, b) \
|
||||
{ \
|
||||
const type _BLOCK_T = a; \
|
||||
a = b; \
|
||||
b = _BLOCK_T; \
|
||||
}
|
||||
|
||||
#define T_DEFINE_less(T) \
|
||||
SORT_PREDICATE(T, T_less__##T) { return a < b; }
|
||||
#define T_DEFINE_greater(T) \
|
||||
SORT_PREDICATE(T, T_greater__##T) { return a > b; }
|
||||
|
||||
#define T_DEFINE_sort(T) \
|
||||
void T_sort__##T(T *start, const T *end, bool (*predicate)(T, T)) { \
|
||||
T *i, *j; \
|
||||
for (i = start; i < end; i++) { \
|
||||
for (j = i; j < end; j++) { \
|
||||
if (predicate(*i, *j)) { \
|
||||
SORT_SWAP(T, *i, *j); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define T_DEFINE_sort_default(T) \
|
||||
void T_sort_default__##T(T *start, const T *end) { \
|
||||
T_sort__##T(start, end, _template_func(T, less)); \
|
||||
}
|
||||
|
||||
#define T_DEFINE_sort_init(T) \
|
||||
_template_func_def(T, less); \
|
||||
_template_func_def(T, greater); \
|
||||
_template_func_def(T, sort); \
|
||||
_template_func_def(T, sort_default);
|
||||
|
||||
#define for_i(i, range, inner) \
|
||||
{ \
|
||||
int i; \
|
||||
for (i = 0; i < range; i++) \
|
||||
inner; \
|
||||
}
|
||||
|
||||
T_DEFINE_sort_init(int);
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int n, a[301] = {0};
|
||||
scanf("%d", &n);
|
||||
for_i(i, n, scanf("%d", a + i));
|
||||
_template_func(int, sort)(a, a + n, _template_func(int, greater));
|
||||
for_i(i, n, printf("%d ", a[i]));
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user