create dev channel

This commit is contained in:
2025-05-07 04:44:30 +09:00
parent 603fca2b20
commit 16a8e59450
426 changed files with 643 additions and 36 deletions

15
zeta/c/completed/1000.c Normal file
View File

@@ -0,0 +1,15 @@
#include<stdio.h>
#define 정수 int
#define 반환 return
#define 출력 printf
#define 입력 scanf
#define 더하기 +
main() {
, ;
("%d %d", &, &);
("%d\n", );
0;
}

54
zeta/c/completed/10469.c Normal file
View File

@@ -0,0 +1,54 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int x, y;
} Point;
int main() {
Point queens[64];
int length = 0;
char temp[8];
Point temp_pos;
bool flag = true;
for (int i = 0; i < 8; i++) {
scanf("%s", temp);
for (int j = 0; j < 8; j++) {
if (temp[j] == '*') {
queens[length].x = i;
queens[length].y = j;
length++;
}
}
}
if (length != 8) flag = false;
Point a, b;
for (int i = 0; i < length; i++) {
if (flag == false) {
break;
}
a = queens[i];
for (int j = 0; j < i; j++) {
b = queens[j];
if (a.x == b.x) {
flag = false;
break;
} else if (a.y == b.y) {
flag = false;
break;
} else if (abs(a.x - b.x) == abs(a.y - b.y)) {
flag = false;
break;
}
}
}
flag ? printf("valid\n") : printf("invalid\n");
return 0;
}

49
zeta/c/completed/10815.c Normal file
View File

@@ -0,0 +1,49 @@
#include <stdio.h>
#include <stdlib.h>
int comp(const void *a, const void *b) {
return *(int *) a - *(int *) b;
}
int is_in(int x, int *cards, int size) {
int begin = 0, end = size - 1, mid;
while (begin <= end) {
mid = (begin + end) / 2;
if (cards[mid] == x) {
return 1;
} else if (cards[mid] > x) {
end = mid - 1;
} else {
begin = mid + 1;
}
}
return 0;
}
int main() {
int N;
scanf("%d", &N);
int cards[N];
for (int i = 0; i < N; i++) {
scanf("%d", &cards[i]);
}
qsort(cards, N, sizeof(int), comp);
int M;
scanf("%d", &M);
int check[M];
for (int i = 0; i < M; i++) {
scanf("%d", &check[i]);
}
for (int i = 0; i < M - 1; i++) {
printf("%d ", is_in(check[i], cards, N));
}
printf("%d\n", is_in(check[M - 1], cards, N));
return 0;
}

18
zeta/c/completed/10818.c Normal file
View File

@@ -0,0 +1,18 @@
#include<stdio.h>
int main() {
int min=1e6; int max=-1e6;
int N; int a;
scanf("%d", &N);
for (int i=0;i<N;i++) {
scanf("%d", &a);
if (a < min) {
min = a;
}
if (a > max){
max = a;
}
}
printf("%d %d", min, max);
}

11
zeta/c/completed/10869.c Normal file
View File

@@ -0,0 +1,11 @@
#include<stdio.h>
int main() {
int a; int b;
scanf("%d %d", &a, &b);
printf("%d\n", a+b);
printf("%d\n", a-b);
printf("%d\n", a*b);
printf("%d\n", a/b);
printf("%d\n", a%b);
}

53
zeta/c/completed/11866.c Normal file
View File

@@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
void solve(int *arr, int n, int k) {
int *temparr = calloc(n, sizeof(int));
if (temparr == NULL) {
fprintf(stderr, "Memory allocation failed\n");
return;
}
int cnt_longlive = 0;
int cnt;
int idx = -1;
for (int i = 0; i < n; i++) {
cnt = 0;
while (cnt < k) {
idx = (idx + 1) % n;
if (temparr[idx] == 0) {
cnt++;
}
}
temparr[idx] = 1;
arr[cnt_longlive++] = idx + 1;
}
free(temparr);
}
void print_result(int *arr, int n) {
printf("<");
for (int i = 0; i < n; i++) {
printf("%d", arr[i]);
if (i != n - 1) {
printf(", ");
}
}
printf(">\n");
}
int main() {
int n, k;
scanf("%d %d", &n, &k);
int *arr = calloc(n, sizeof(int));
if (arr == NULL) {
fprintf(stderr, "Memory allocation failed\n");
return 1;
}
solve(arr, n, k);
print_result(arr, n);
free(arr);
return 0;
}

51
zeta/c/completed/14425.c Normal file
View File

@@ -0,0 +1,51 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int STR_LEN = 501;
int comp(const void *a, const void *b) {
return strcmp((char *) a, (char *) b);
}
int is_in(char *a, char (*S)[STR_LEN], int N) {
// binary search
int low = 0, high = N - 1;
while (low <= high) {
int mid = (low + high) / 2;
int k = (int) strcmp(a, S[mid]);
if (k == 0) return 1;
else if (k < 0)
high = mid - 1;
else if (k > 0)
low = mid + 1;
}
return 0;
}
int main() {
int N, M;
scanf("%d %d", &N, &M);
char S[N][STR_LEN];
char check[M][STR_LEN];
for (int i = 0; i < N; i++) {
scanf("%s", (S[i]));
}
for (int i = 0; i < M; i++) {
scanf("%s", (check[i]));
}
qsort(S, N, sizeof(char) * 501, comp);
int count = 0;
for (int i = 0; i < M; i++) {
count += is_in((check[i]), S, N);
}
printf("%d\n", count);
return 0;
}

50
zeta/c/completed/14709.c Normal file
View File

@@ -0,0 +1,50 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct IntPair {
int first;
int second;
} IntPair;
bool fox(int N, IntPair *pairs) {
bool _b13 = false;
bool _b14 = false;
bool _b34 = false;
for (int i = 0; i < N; i++) {
if (pairs[i].first == 2 || pairs[i].first == 5 || pairs[i].second == 2 || pairs[i].second == 5) return false;
if (pairs[i].first == 1) {
if (pairs[i].second == 3) {
_b13 = true;
} else if (pairs[i].second == 4) {
_b14 = true;
}
} else if (pairs[i].first == 3) {
if (pairs[i].second == 1) {
_b13 = true;
} else if (pairs[i].second == 4) {
_b34 = true;
}
} else if (pairs[i].first == 4) {
if (pairs[i].second == 1) {
_b14 = true;
} else if (pairs[i].second == 3) {
_b34 = true;
}
}
}
return _b13 && _b14 && _b34;
}
int main(void) {
int N;
scanf("%d", &N);
IntPair *pairs = (int *) calloc(N, sizeof(IntPair));
for (int i = 0; i < N; i++) {
scanf("%d %d", &pairs[i].first, &pairs[i].second);
}
bool isFox = fox(N, pairs);
isFox ? printf("Wa-pa-pa-pa-pa-pa-pow!\n") : printf("Woof-meow-tweet-squeek\n");
return 0;
}

102
zeta/c/completed/16174.c Normal file
View File

@@ -0,0 +1,102 @@
#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 1000000
typedef struct {
int x;
int y;
} Position;
Position stack[MAX_SIZE];
int top = -1;
void push(Position item) {
stack[++top] = item;
}
Position pop() {
return stack[top--];
}
int is_empty() {
if (top == -1) {
return 1;
} else {
return 0;
}
}
int main() {
int N;
scanf("%d", &N);
int **A = (int **) calloc(N, sizeof(int *));
A[0] = (int *) calloc(N * N, sizeof(int));
for (int i = 1; i < N; i++) {
A[i] = A[i - 1] + N;
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
scanf("%d", &A[i][j]);
}
}
int **V = (int **) calloc(N, sizeof(int *));
V[0] = (int *) calloc(N * N, sizeof(int));
for (int i = 1; i < N; i++) {
V[i] = V[i - 1] + N;
}
int flag = 0;
Position nowainit;
nowainit.x = 0;
nowainit.y = 0;
push(nowainit);
Position now;
Position target;
int amount;
while (!is_empty()) {
now = pop();
amount = A[now.x][now.y];
if (V[now.x][now.y]) {
continue;
}
V[now.x][now.y] = 1;
if (amount == 0) {
continue;
} else if (amount == -1) {
flag = 1;
break;
}
if (now.x + amount >= N) {
} else {
target.x = now.x + amount;
target.y = now.y;
push(target);
}
if (now.y + amount >= N) {
} else {
target.x = now.x;
target.y = now.y + amount;
push(target);
}
}
if (flag) printf("HaruHaru");
else
printf("Hing");
free(A[0]);
free(A);
free(V[0]);
free(V);
return 0;
}

80
zeta/c/completed/1620.c Normal file
View File

@@ -0,0 +1,80 @@
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LENGTH 21
typedef struct _Element {
int index;
char name[MAX_LENGTH];
} Element;
int ecomp(const void *a, const void *b) {
int c = strcmp((*(Element *) a).name, (*(Element *) b).name);
return c;
}
Element binsearch_idx(Element *dict, int N, int x) {
int start = 0;
int end = N - 1;
int mid;
while (start <= end) {
mid = (start + end) / 2;
if (dict[mid].index == x) {
break;
} else if (dict[mid].index > x) {
end = mid - 1;
} else {
start = mid + 1;
}
}
return dict[mid];
}
Element binsearch_str(Element *dict, int N, char *x) {
int start = 0;
int end = N - 1;
int mid;
while (start <= end) {
mid = (start + end) / 2;
int c = strcmp(dict[mid].name, x);
if (c == 0) {
break;
} else if (c > 0) {
end = mid - 1;
} else {
start = mid + 1;
}
}
return dict[mid];
}
int main() {
int N, M;
scanf("%d %d", &N, &M);
Element *dictionary = (Element *) calloc(N, sizeof(Element));
Element *str_dictionary = (Element *) calloc(N, sizeof(Element));
for (int i = 0; i < N; i++) {
scanf("%s", dictionary[i].name);
dictionary[i].index = i + 1;
}
memmove(str_dictionary, dictionary, sizeof(Element) * N);
qsort(str_dictionary, N, sizeof(Element), ecomp);
for (int i = 0; i < M; i++) {
char temp[MAX_LENGTH];
scanf("%s", temp);
Element e;
if (temp[0] <= '9' && temp[0] >= '0') {
e = binsearch_idx(dictionary, N, atoi(temp));
printf("%s\n", e.name);
} else {
e = binsearch_str(str_dictionary, N, temp);
printf("%d\n", e.index);
}
}
return 0;
}

51
zeta/c/completed/16439.c Normal file
View File

@@ -0,0 +1,51 @@
#include <stdio.h>
#include <stdlib.h>
int max3(int x, int y, int z) {
if (x > y)
if (x > z)
return x;
else
return z;
else if (y > z)
return y;
else
return z;
}
int comp(const void *a, const void *b) {
return (*(int *) b - *(int *) a);
}
int main() {
int N, M, temp = 0;
scanf("%d %d", &N, &M);
int *scores = (int *) calloc(N * M, sizeof(int));
int *maxes = (int *) calloc(M * M * M, sizeof(int));
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
scanf("%d", scores + M * i + j);
}
}
for (int i = 0; i < M; i++) {
for (int j = 0; j < M; j++) {
if (j == i) continue;
for (int k = 0; k < M; k++) {
if (k == j || k == i) continue;
temp = 0;
for (int n = 0; n < N; n++) {
temp += max3(scores[M * n + i], scores[M * n + j], scores[M * n + k]);
}
maxes[M * M * i + M * j + k] = temp;
}
}
}
qsort(maxes, M * M * M, sizeof(int), comp);
printf("%d", maxes[0]);
free(scores);
free(maxes);
return 0;
}

61
zeta/c/completed/17387.c Normal file
View File

@@ -0,0 +1,61 @@
#include <stdio.h>
#include <stdlib.h>
typedef long long LL;
int ccw(int x1, int y1, int x2, int y2, int x3, int y3) {
LL s = (LL) (x2 - x1) * (LL) (y3 - y1) - (LL) (y2 - y1) * (LL) (x3 - x1);
if (s > 0) return 1;
if (s < 0) return -1;
return 0;
}
int compare_leq(int x1, int y1, int x2, int y2) {
if (x1 == x2) {
return y1 <= y2;
}
return x1 <= x2;
}
int isIntersect(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
int d1 = ccw(x1, y1, x2, y2, x3, y3);
int d2 = ccw(x1, y1, x2, y2, x4, y4);
int d3 = ccw(x3, y3, x4, y4, x1, y1);
int d4 = ccw(x3, y3, x4, y4, x2, y2);
int c1 = d1 * d2;
int c2 = d3 * d4;
if (c1 == 0 && c2 == 0) {
if (compare_leq(x2, y2, x1, y1)) {
int temp = x1;
x1 = x2;
x2 = temp;
temp = y1;
y1 = y2;
y2 = temp;
}
if (compare_leq(x4, y4, x3, y3)) {
int temp = x3;
x3 = x4;
x4 = temp;
temp = y3;
y3 = y4;
y4 = temp;
}
return (compare_leq(x1, y1, x4, y4) &&
compare_leq(x3, y3, x2, y2));
}
return c1 <= 0 && c2 <= 0;
}
int main() {
int x1, y1, x2, y2;
int x3, y3, x4, y4;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
scanf("%d %d %d %d", &x3, &y3, &x4, &y4);
printf("%d\n", isIntersect(x1, y1, x2, y2, x3, y3, x4, y4));
return 0;
}

56
zeta/c/completed/1783.c Normal file
View File

@@ -0,0 +1,56 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// M 개수에 주요한 변수를 가지고 있음. N = 1이면 무조건 1
// 1 1 1 1 1
// 1 1 1 1 1
int sick_knight(int N, int M) {
if (N == 1) {
return 1;
} else if (M == 1) {
return 1;
} else if (M == 2) {
if (N < 3) {
return 1;
} else {
return 2;
}
} else if (M == 3) {
if (N < 3) {
return 2;
} else {
return 3;
}
} else if (M == 4) {
if (N < 3) {
return 2;
} else {
return 4;
}
} else if (M == 5) {
if (N < 3) {
return 3;
} else {
return 4;
}
} else if (M == 6) {
if (N < 3) {
return 3;
} else {
return 4;
}
} else if (M >= 7) {
if (N < 3) {
return 4;
} else {
return M - 2;
}
}
}
int main() {
int N, M;
scanf("%d %d", &N, &M);
printf("%d\n", sick_knight(N, M));
return 0;
}

69
zeta/c/completed/18870.c Normal file
View File

@@ -0,0 +1,69 @@
#include <stdio.h>
#include <stdlib.h>
typedef struct Honeycomb {
int x;
int loc;
int compressed;
} Honeycomb;
int compare_x(const void *a, const void *b) {
Honeycomb A = *(Honeycomb *) a;
Honeycomb B = *(Honeycomb *) b;
if (A.x > B.x) {
return 1;
} else if (A.x < B.x) {
return -1;
} else {
return 0;
}
}
int compare_loc(const void *a, const void *b) {
Honeycomb A = *(Honeycomb *) a;
Honeycomb B = *(Honeycomb *) b;
if (A.loc > B.loc) {
return 1;
} else if (A.loc < B.loc) {
return -1;
} else {
return 0;
}
}
// 좌표 압축 알고리즘
void compress(int N, Honeycomb *arr) {
qsort(arr, N, sizeof(Honeycomb), compare_x);
for (int i = 1; i < N; i++) {
if (arr[i].x == arr[i - 1].x) {
arr[i].compressed = arr[i - 1].compressed;
} else {
arr[i].compressed = arr[i - 1].compressed + 1;
}
}
qsort(arr, N, sizeof(Honeycomb), compare_loc);
}
// C11(Clang)에서 런타임에러: 백준 clang에서 qsort가 정렬을 제대로 하지 못하는 문제
int main() {
int N;
scanf("%d", &N);
Honeycomb *arr;;
arr = (Honeycomb *) calloc(N, sizeof(Honeycomb));
for (int i = 0; i < N; i++) {
scanf("%d", &arr[i].x);
arr[i].loc = i;
arr[i].compressed = 0;
}
compress(N, arr);
for (int i = 0; i < N - 1; i++) {
printf("%d ", arr[i].compressed);
}
printf("%d\n", arr[N - 1].compressed);
free(arr);
return 0;
}

18
zeta/c/completed/19532.c Normal file
View File

@@ -0,0 +1,18 @@
#include <stdio.h>
#include <stdlib.h>
int main() {
int a, b, c, d, e, f;
scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
for (int x = -999; x <= 999; x++) {
for (int y = -999; y <= 999; y++) {
if (a * x + b * y == c && d * x + e * y == f) {
printf("%d %d\n", x, y);
goto finish;
}
}
}
finish:
return 0;
}

54
zeta/c/completed/19592.c Normal file
View File

@@ -0,0 +1,54 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int compare(const void *first, const void *second) {
if (*(int *) first < *(int *) second)
return 1;
else if (*(int *) first > *(int *) second)
return -1;
else
return 0;
}
int main() {
int T;
scanf("%d", &T);
int N, X, Y;
int *V;
for (int i = 0; i < T; i++) {
scanf("%d %d %d", &N, &X, &Y);
V = (int *) calloc(N, sizeof(int));
for (int j = 0; j < N; j++) {
scanf("%d", &V[j]);
}
int my_speed = V[N - 1];
qsort(V, N - 1, sizeof(int), compare);
int rival_speed = V[0];
double rival_time;
if (my_speed > rival_speed) {
printf("%d\n", 0);
free(V);
continue;
} else {
rival_time = (double) X / (double) rival_speed;
}
double Z;
int iZ;
if (rival_time >= 1) {
Z = X - (rival_time - 1) * my_speed;
} else {
Z = rival_speed + 1;
}
iZ = floor(Z + 1);
if (iZ > Y) {
printf("%d\n", -1);
} else {
printf("%d\n", iZ);
}
free(V);
}
return 0;
}

41
zeta/c/completed/19637.c Normal file
View File

@@ -0,0 +1,41 @@
#include <stdbool.h>
#include <stdio.h>
typedef struct TitleCondition {
char title[12];
int condition;
} TitleCondition;
TitleCondition total[100000];
int N, M;
// tc[i-1] < x <= tc[i]일 때, tc[i]
TitleCondition *get_title(int x) {
int start = -1, end = N;
int mid;
while (start + 1 < end) {
mid = (start + end) / 2;
if (total[mid].condition < x) {
start = mid;
} else {
end = mid;
}
}
return total + end;
}
int main() {
scanf("%d %d", &N, &M);
for (int i = 0; i < N; i++) {
scanf("%s %d", &total[i].title, &total[i].condition);
}
int temp;
for (int i = 0; i < M; i++) {
scanf("%d", &temp);
printf("%s\n", get_title(temp)->title);
}
return 0;
}

37
zeta/c/completed/20153.c Normal file
View File

@@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#define max(x, y) (x) > (y) ? (x) : (y)
// 영웅이 표기법 31 -> 16 + 8 + 4 + 2 + 1 11111
// 5(101) = 4 + 1, 7(111) = 4 + 2 + 1, 11 = 8 + 2 + 1 1011
// all 1001 5빼면 1100(12) 7빼면 1110(14) 당첨
// 하나 빼기
// 짝수면 제거 --> 사라지면 없음
// 홀수면 생존 --> 생기면 뭐
int (int N, int *A) {
int all = 0;
for (int i = 0; i < N; i++) {
all ^= A[i];
}
int M = all;
for (int i = 0; i < N; i++) {
M = max(M, all ^ A[i]);
}
return M;
}
int main() {
int power[22] = {0};
int N;
scanf("%d", &N);
int *A = (int *) calloc(N, sizeof(int));
for (int i = 0; i < N; i++) {
scanf("%d", A + i);
}
int r = (N, A);
printf("%d%d\n", r, r);
return 0;
}

9
zeta/c/completed/24263.c Normal file
View File

@@ -0,0 +1,9 @@
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
printf("%d\n%d\n", n, 1);
return 0;
}

8
zeta/c/completed/24264.c Normal file
View File

@@ -0,0 +1,8 @@
#include <stdio.h>
int main() {
long long n;
scanf("%lld", &n);
printf("%lld\n%d\n", n * n, 2);
return 0;
}

8
zeta/c/completed/24265.c Normal file
View File

@@ -0,0 +1,8 @@
#include <stdio.h>
int main() {
long long n;
scanf("%lld", &n);
printf("%lld\n%d\n", n * (n - 1L) / 2L, 2);
return 0;
}

8
zeta/c/completed/24266.c Normal file
View File

@@ -0,0 +1,8 @@
#include <stdio.h>
int main() {
long long n;
scanf("%lld", &n);
printf("%lld\n%d\n", n * n * n, 3);
return 0;
}

8
zeta/c/completed/24267.c Normal file
View File

@@ -0,0 +1,8 @@
#include <stdio.h>
int main() {
long long n;
scanf("%lld", &n);
printf("%lld\n%d\n", n * (n - 1L) * (n - 2L) / 6L, 3);
return 0;
}

18
zeta/c/completed/24313.c Normal file
View File

@@ -0,0 +1,18 @@
#include <stdio.h>
int main() {
int a1, a0, c, n0;
scanf("%d %d\n%d\n%d", &a1, &a0, &c, &n0);
int cond = 1;
for (int i = n0; i <= 100; i++) {
if (a1 * i + a0 > c * i) {
cond = 0;
break;
}
}
printf("%d\n", cond);
return 0;
}

40
zeta/c/completed/24368.c Normal file
View File

@@ -0,0 +1,40 @@
#include <stdio.h>
int check(a2, a1, a0, c, n0) {
if (c - a2 < 0) {
return 0;
} else if (c - a2 == 0) {
if (a1 == 0) {
if (-a0 >= 0) {
return 1;
}
} else if (-a1 > 0) {
if ((-a1) * n0 - a0 >= 0) {
return 1;
}
}
return 0;
} else {
int p = (c - a2) * n0 * n0 - a1 * n0 - a0;
if (p >= 0) {
int d = a1 * a1 + 4 * (c - a2) * a0;
if (d <= 0) {
return 1;
} else {
double axis = (double) (a1) / (2.0 * (double) (c - a2));
if (n0 >= axis) {
return 1;
}
}
}
return 0;
}
}
int main() {
int a2, a1, a0, c, n0;
scanf("%d %d %d", &a2, &a1, &a0);
scanf("%d", &c);
scanf("%d", &n0);
printf("%d\n", check(a2, a1, a0, c, n0));
}

27
zeta/c/completed/25305.c Normal file
View File

@@ -0,0 +1,27 @@
#include <stdio.h>
int main() {
int N, k;
scanf("%d %d\n", &N, &k);
int [N + 1];
int ;
for (int i = 0; i < N; i++) {
scanf("%d", &[i]);
}
for (int i = 0; i < N - 1; i++) {
for (int j = 0; j < N - 1; j++) {
if ([j] < [j + 1]) {
= [j];
[j] = [j + 1];
[j + 1] = ;
}
}
}
printf("%d\n", [k - 1]);
}

5
zeta/c/completed/2557.c Normal file
View File

@@ -0,0 +1,5 @@
#include<stdio.h>
int main() {
printf("Hello World!");
}

30
zeta/c/completed/2587.c Normal file
View File

@@ -0,0 +1,30 @@
#include <stdio.h>
int main() {
int [5];
int = 0;
int ;
scanf("%d\n%d\n%d\n%d\n%d", &[0], &[1], &[2], &[3], &[4]);
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 4; j++) {
if ([j] > [j + 1]) {
= [j];
[j] = [j + 1];
[j + 1] = ;
}
}
}
for (int i = 0; i < 5; i++) {
+= [i];
}
printf("%d\n", / 5);
printf("%d\n", [2]);
return 0;
}

100
zeta/c/completed/26083.c Normal file
View File

@@ -0,0 +1,100 @@
#include <stdio.h>
typedef struct Date {
int year, month, day;
} Date;
Date *newDate(int year, int month, int day) {
if (0 <= year && year <= 99) {
if (1 <= month && month <= 12) {
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
if (1 <= day && day <= 31) {
Date *date = (Date *) malloc(sizeof(Date));
date->year = year;
date->month = month;
date->day = day;
return date;
}
} else if (month == 2 && year % 4 == 0) {
if (1 <= day && day <= 29) {
Date *date = (Date *) malloc(sizeof(Date));
date->year = year;
date->month = month;
date->day = day;
return date;
}
} else if (month == 2 && year % 4 != 0) {
if (1 <= day && day <= 28) {
Date *date = (Date *) malloc(sizeof(Date));
date->year = year;
date->month = month;
date->day = day;
return date;
}
} else {
if (1 <= day && day <= 30) {
Date *date = (Date *) malloc(sizeof(Date));
date->year = year;
date->month = month;
date->day = day;
return date;
}
}
}
}
return NULL;
}
void delDate(Date *date) {
free(date);
date = NULL;
}
int valid(Date *x, Date now) {
if (x == NULL) {
return 1;
}
if (x->year < now.year) {
return 0;
} else if (x->year > now.year) {
return 1;
}
if (x->month < now.month) {
return 0;
} else if (x->month > now.month) {
return 1;
}
if (x->day < now.day) {
return 0;
} else if (x->day >= now.day) {
return 1;
}
return 0;
}
int main() {
int N;
Date NOW;
int first, second, third;
scanf("%d %d %d", &NOW.year, &NOW.month, &NOW.day);
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d %d %d", &first, &second, &third);
Date *d1 = newDate(first, second, third);
Date *d2 = newDate(third, second, first);
Date *d3 = newDate(third, first, second);
if (d1 == NULL && d2 == NULL && d3 == NULL) {
printf("invalid\n");
} else if (valid(d1, NOW) && valid(d2, NOW) && valid(d3, NOW)) {
printf("safe\n");
} else {
printf("unsafe\n");
}
delDate(d1);
delDate(d2);
delDate(d3);
}
}

74
zeta/c/completed/2615.c Normal file
View File

@@ -0,0 +1,74 @@
#include <stdio.h>
#include <stdlib.h>
int get(int map[], int x, int y) {
return map[19 * x + y];
}
int main() {
int Map[19 * 19];
int dx[] = {1, 0, 1, 1};
int dy[] = {0, 1, 1, -1};
int flag;
int last_color;
int last_pos_x, last_pos_y;
for (int i = 0; i < 19; i++) {
for (int j = 0; j < 19; j++) {
scanf("%d", Map + i + j * 19);
}
}
for (int x = 0; x < 19; x++) {
for (int y = 0; y < 19; y++) {
int now = get(Map, x, y);
if (now == 0) {
continue;
} else {
for (int d = 0; d < 4; d++) {
if (19 > x - dx[d] && x - dx[d] >= 0 && 19 > y - dy[d] && y - dy[d] >= 0) {
if (get(Map, x - dx[d], y - dy[d]) == now) {
flag = 0;
continue;
}
}
flag = 1;
for (int i = 1; i < 5; i++) {
if (19 > x + i * dx[d] && x + i * dx[d] >= 0 && 19 > y + i * dy[d] && y + i * dy[d] >= 0) {
if (get(Map, x + i * dx[d], y + i * dy[d]) != now) {
flag = 0;
break;
}
} else {
flag = 0;
break;
}
}
if (flag) {
if (19 > x + 5 * dx[d] && x + 5 * dx[d] >= 0 && 19 > y + 5 * dy[d] && y + 5 * dy[d] >= 0) {
if (get(Map, x + 5 * dx[d], y + 5 * dy[d]) == now) {
flag = 0;
continue;
}
}
}
if (flag) {
break;
}
}
}
if (flag) {
last_color = now;
last_pos_x = x;
last_pos_y = y;
break;
}
}
if (flag) {
break;
}
}
flag ? printf("%d\n%d %d\n", last_color, last_pos_y + 1, last_pos_x + 1) : printf("%d\n", 0);
return 0;
}

27
zeta/c/completed/2828.c Normal file
View File

@@ -0,0 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
int main() {
int N, M, J, cnt = 0, tmp, now = 1, flag;
scanf("%d %d", &N, &M);
scanf("%d", &J);
int *pos = (int *) calloc(J, sizeof(int));
for (int i = 0; i < J; i++) {
scanf("%d", pos + i);
}
for (int i = 0; i < J; i++) {
flag = 1;
while (flag) {
if (now <= pos[i] && pos[i] <= now + M - 1) {
flag = 0;
} else if (now > pos[i]) {
now--;
cnt++;
} else {
now++;
cnt++;
}
}
}
printf("%d\n", cnt);
}

60
zeta/c/completed/28702.c Normal file
View File

@@ -0,0 +1,60 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int getNextInt(char **s1) {
for (int i = 0; i < 3; i++) {
if (s1[i][0] == 'F' || s1[i][0] == 'B') {
continue;
} else {
return atoi(s1[i]) + (3 - i);
}
}
return 0;
}
void getNext(char *s2, char **s1) {
int ni = getNextInt(s1);
if (ni % 3 == 0 && ni % 5 == 0) {
strcpy(s2, "FizzBuzz");
} else if (ni % 3 == 0) {
strcpy(s2, "Fizz");
} else if (ni % 5 == 0) {
strcpy(s2, "Buzz");
} else {
sprintf(s2, "%d", ni);
}
}
int main() {
char **s1 = malloc(sizeof(char *) * 3);
if (s1 == NULL) {
exit(1);
}
for (int i = 0; i < 3; i++) {
s1[i] = malloc(sizeof(char) * 10);
if (s1[i] == NULL) {
exit(1);
}
}
for (int i = 0; i < 3; i++) {
scanf("%s", s1[i]);
}
char *s2 = malloc(sizeof(char) * 10);
if (s2 == NULL) {
exit(1);
}
getNext(s2, s1);
printf("%s\n", s2);
free(s2);
for (int i = 0; i < 3; i++) {
free(s1[i]);
}
free(s1);
return 0;
}

60
zeta/c/completed/31825.c Normal file
View File

@@ -0,0 +1,60 @@
#include <stdio.h>
#include <stdlib.h>
typedef struct Alphabets {
char *string;
int len;
} Alphabets;
char shift(char x) {
if (x == 90) return 65;
else
return x + 1;
}
void querry_shift(Alphabets *alphas, int left, int right) {
for (int i = left - 1; i < right; i++) {
*(alphas->string + i) = shift(*(alphas->string + i));
}
}
int querry_string(Alphabets *alphas, int left, int right) {
int cnt = 0;
char head = 0, now;
for (int i = left - 1; i < right; i++) {
now = *(alphas->string + i);
if (head != now) {
head = now;
cnt++;
}
}
return cnt;
}
int querry(Alphabets *alphas, int left, int right, int type) {
if (type == 2) {
querry_shift(alphas, left, right);
return -1;
} else {
return querry_string(alphas, left, right);
}
}
int main() {
int N, Q, left, right, type, ret;
scanf("%d %d", &N, &Q);
Alphabets alphas;
alphas.len = N;
alphas.string = (char *) malloc(alphas.len * sizeof(char));
scanf("%s", alphas.string);
for (int i = 0; i < Q; i++) {
scanf("%d %d %d", &type, &left, &right);
ret = querry(&alphas, left, right, type);
if (ret < 0) {
continue;
} else {
printf("%d\n", ret);
}
}
free(alphas.string);
}

40
zeta/c/completed/7785.c Normal file
View File

@@ -0,0 +1,40 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct _Item {
char name[6];
char isin;
} Item;
int comp(const void *a, const void *b) {
int cmp = strcmp((*(Item *) a).name, (*(Item *) b).name);
return -cmp;
}
int main() {
int N;
scanf("%d", &N);
Item res[N + 1];
for (int i = 0; i < N; i++) {
char temp[6];
scanf("%s %s", res[i].name, temp);
if (temp[0] == 'e') {
res[i].isin = 1;
} else {
res[i].isin = 0;
}
}
qsort(res, N, sizeof(Item), comp);
for (int i = 0; i < N; i++) {
if (comp(&res[i], &res[i + 1]) == 0) {
i++;
} else {
printf("%s\n", res[i].name);
}
}
return 0;
}