This commit is contained in:
Bluemangoo 2025-03-11 20:29:47 +08:00
parent 747dcefe75
commit f626c98e12
Signed by: Bluemangoo
GPG Key ID: F2F7E46880A1C4CF
8 changed files with 152 additions and 16 deletions

43
.vscode/c.code-snippets vendored Normal file
View File

@ -0,0 +1,43 @@
{
"Init file": {
"prefix": "init",
"body": ["#include <stdio.h>", "", "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"
}
}

23
0311-t/1.c Normal file
View File

@ -0,0 +1,23 @@
#include <stdio.h>
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);
}

View File

@ -1,23 +1,16 @@
#include <stdio.h>
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;
}

10
0311/2.c Normal file
View File

@ -0,0 +1,10 @@
#include <stdio.h>
int main() {
int n, cnt = 0;
scanf("%d", &n);
printf("%d", (1 + n) * n / 2);
return 0;
while (0) {
}
}

11
0311/3.c Normal file
View File

@ -0,0 +1,11 @@
#include <stdio.h>
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;
}

10
0311/4.c Normal file
View File

@ -0,0 +1,10 @@
#include <stdio.h>
int main() {
int i, cnt = 0;
for (i = 1; i <= 597; i += 4) {
cnt += i * (i + 2);
}
printf("%d", cnt);
return 0;
}

28
0311/5.c Normal file
View File

@ -0,0 +1,28 @@
#include <stdio.h>
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;
}

18
0311/6.c Normal file
View File

@ -0,0 +1,18 @@
#include <stdio.h>
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;
}