From f626c98e12de4549d31ec3872972a6aab3b2f886 Mon Sep 17 00:00:00 2001 From: Bluemangoo Date: Tue, 11 Mar 2025 20:29:47 +0800 Subject: [PATCH] 0311 --- .vscode/c.code-snippets | 43 +++++++++++++++++++++++++++++++++++++++++ 0311-t/1.c | 23 ++++++++++++++++++++++ 0311/1.c | 25 +++++++++--------------- 0311/2.c | 10 ++++++++++ 0311/3.c | 11 +++++++++++ 0311/4.c | 10 ++++++++++ 0311/5.c | 28 +++++++++++++++++++++++++++ 0311/6.c | 18 +++++++++++++++++ 8 files changed, 152 insertions(+), 16 deletions(-) create mode 100644 .vscode/c.code-snippets create mode 100644 0311-t/1.c create mode 100644 0311/2.c create mode 100644 0311/3.c create mode 100644 0311/4.c create mode 100644 0311/5.c create mode 100644 0311/6.c diff --git a/.vscode/c.code-snippets b/.vscode/c.code-snippets new file mode 100644 index 0000000..5083568 --- /dev/null +++ b/.vscode/c.code-snippets @@ -0,0 +1,43 @@ +{ + "Init file": { + "prefix": "init", + "body": ["#include ", "", "int main() {", " return 0;", "}"], + "description": "Init file" + }, + "Define function swap two var with macro": { + "prefix": "fn_swap_macro", + "body": ["#define swap(a, b) { typeof(a) temp = a; a = b; b = temp; }"], + "description": "Define function swap two var with macro" + }, + "Define function swap two int": { + "prefix": "fn_swap", + "body": [ + "void swap(int *a, int *b) {", + " int temp = *a;", + " *a = *b;", + " *b = temp;", + "}" + ], + "description": "Define function swap two int" + }, + "Define function put bool": { + "prefix": "fn_putbool", + "body": ["#define putbool(x) (printf(\"%s\", (x) ? \"TRUE\" : \"FALSE\"))"], + "description": "Define function put bool" + }, + "Define function max": { + "prefix": "fake_max", + "body": ["#define max(i, j) (((i) > (j)) ? (i) : (j))"], + "description": "Define function max" + }, + "Define function min": { + "prefix": "fake_min", + "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" + } +} diff --git a/0311-t/1.c b/0311-t/1.c new file mode 100644 index 0000000..4d0f11c --- /dev/null +++ b/0311-t/1.c @@ -0,0 +1,23 @@ +#include + +void swap(char *a, char *b) { + char temp = *a; + *a = *b; + *b = temp; +} + +int main() { + char num[3]; + scanf("%s", num); + + if (num[2] > num[1]) { + swap(num + 2, num + 1); + } + if (num[1] > num[0]) { + swap(num + 1, num); + } + if (num[2] > num[1]) { + swap(num + 2, num + 1); + } + printf("%s\n", num); +} \ No newline at end of file diff --git a/0311/1.c b/0311/1.c index 4d0f11c..7b409c7 100644 --- a/0311/1.c +++ b/0311/1.c @@ -1,23 +1,16 @@ #include -void swap(char *a, char *b) { - char temp = *a; - *a = *b; - *b = temp; -} - int main() { - char num[3]; - scanf("%s", num); - - if (num[2] > num[1]) { - swap(num + 2, num + 1); + int m, n; + scanf("%d %d", &m, &n); + if (m % 2 != 0) { + m++; } - if (num[1] > num[0]) { - swap(num + 1, num); + if (n % 2 != 0) { + n--; } - if (num[2] > num[1]) { - swap(num + 2, num + 1); + while (0) { } - printf("%s\n", num); + printf("%d", (m + n) * (n - m + 2) / 2 / 2); + return 0; } \ No newline at end of file diff --git a/0311/2.c b/0311/2.c new file mode 100644 index 0000000..6c7425f --- /dev/null +++ b/0311/2.c @@ -0,0 +1,10 @@ +#include + +int main() { + int n, cnt = 0; + scanf("%d", &n); + printf("%d", (1 + n) * n / 2); + return 0; + while (0) { + } +} \ No newline at end of file diff --git a/0311/3.c b/0311/3.c new file mode 100644 index 0000000..efb148b --- /dev/null +++ b/0311/3.c @@ -0,0 +1,11 @@ +#include + +int main() { + int n, cnt = 0, i; + scanf("%d", &n); + for (i = 1; i <= n; i++) { + cnt += (1 + i) * i / 2; + } + printf("%d", cnt); + return 0; +} \ No newline at end of file diff --git a/0311/4.c b/0311/4.c new file mode 100644 index 0000000..d799a7e --- /dev/null +++ b/0311/4.c @@ -0,0 +1,10 @@ +#include + +int main() { + int i, cnt = 0; + for (i = 1; i <= 597; i += 4) { + cnt += i * (i + 2); + } + printf("%d", cnt); + return 0; +} \ No newline at end of file diff --git a/0311/5.c b/0311/5.c new file mode 100644 index 0000000..0c9e249 --- /dev/null +++ b/0311/5.c @@ -0,0 +1,28 @@ +#include +void swap(int *a, int *b) { + int temp = *a; + *a = *b; + *b = temp; +} + +int main() { + int m, n; + scanf("%d %d", &m, &n); + if (m > n) { + swap(&m, &n); + } + if (m % 2 == 0) { + m++; + } + if (n % 2 == 0) { + n--; + } + if (m > n) { + printf("0"); + return 0; + } + while (0) { // Fake loop + } + printf("%d", (m + n) * (n - m + 2) / 2 / 2); + return 0; +} \ No newline at end of file diff --git a/0311/6.c b/0311/6.c new file mode 100644 index 0000000..1e15561 --- /dev/null +++ b/0311/6.c @@ -0,0 +1,18 @@ +#include + +int main() { + int m, n, max = -1, min = 51, i; + scanf("%d %d", &m, &n); + + for (i = 0; i < m * n; i++) { + int a; + scanf("%d", &a); + if (a > max) + max = a; + if (a < min) + min = a; + } + printf("%d", max - min); + + return 0; +} \ No newline at end of file