complete 11866.c 28702.c
This commit is contained in:
53
zeta_C/completed/11866.c
Normal file
53
zeta_C/completed/11866.c
Normal 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;
|
||||||
|
}
|
||||||
60
zeta_C/completed/28702.c
Normal file
60
zeta_C/completed/28702.c
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user