added days 5 and 6

This commit is contained in:
Antonia 2022-12-07 14:40:21 +01:00
parent cec45601ec
commit 5d06b5f55c
5 changed files with 181 additions and 1 deletions

53
05.c Normal file
View file

@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 50
char stack[10*SIZE];
int ptr[10];
int move(int source, int dest) {
ptr[dest]--;
stack[ptr[dest]] = stack[ptr[source]];
ptr[source]++;
}
int insert(int index, char val) {
stack[ptr[index]] = val;
ptr[index]++;
}
void init_ptrs() {
for (int i=0; i<10; i++) {
ptr[i] = i*SIZE;
}
}
int main () {
char cur[20];
int cur_sum = 0;
int max = 0;
init_ptrs();
int k = 1;
while (fgets(cur,5,stdin) !=NULL) {
if (strlen(cur) < 4 || cur[1] == '1') break;
if (cur[1] != ' ') {
insert(k,cur[1]);
}
k++;
if (k > 9) k=1;
}
init_ptrs();
char c;
while (c = getchar(), c != '\n'); // skip lines
while (c = getchar(), c != '\n'); // skip lines
int q, src, dst;
while (scanf("move %d from %d to %d\n", &q, &src, &dst) != EOF) {
for (int k=0; k<q ; k++)
move(src,dst);
}
for (int i=1; i<10; i++)
putchar(stack[ptr[i]]);
}

52
05_02.c Normal file
View file

@ -0,0 +1,52 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 50
char stack[10*SIZE];
int ptr[10];
int move(int source, int dest, int q) {
ptr[dest]-= q;
memcpy(stack + ptr[dest], stack + ptr[source], q);
ptr[source]+=q;
}
int insert(int index, char val) {
stack[ptr[index]] = val;
ptr[index]++;
}
void init_ptrs() {
for (int i=0; i<10; i++) {
ptr[i] = i*SIZE;
}
}
int main () {
char cur[20];
int cur_sum = 0;
int max = 0;
init_ptrs();
int k = 1;
while (fgets(cur,5,stdin) !=NULL) {
if (strlen(cur) < 4 || cur[1] == '1') break;
if (cur[1] != ' ') {
insert(k,cur[1]);
}
k++;
if (k > 9) k=1;
}
init_ptrs();
char c;
while (c = getchar(), c != '\n'); // skip lines
while (c = getchar(), c != '\n'); // skip lines
int q, src, dst;
while (scanf("move %d from %d to %d\n", &q, &src, &dst) != EOF) {
move(src,dst,q);
}
for (int i=1; i<10; i++)
putchar(stack[ptr[i]]);
}

33
06.c Normal file
View file

@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char c[5];
int is_equal () {
return !(c[0] == c[1] || c[0] == c[2] || c[0] == c[3] || c[1] == c[2] || c[1] == c[3] || c[2] == c[3]);
}
int main () {
int k = 0;
int j = 1;
char f;
c[5] = 0;
while (j < 5) {
c[k] = getchar();
k++;
j++;
}
while ((f = getchar()) != EOF) {
k %=4;
printf("%d %s f:%c\n",k,c,f);
if (is_equal()) break;
c[k] = f;
k++;
j++;
}
printf("%d\n", j-1);
}

42
06_02.c Normal file
View file

@ -0,0 +1,42 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char c[15];
int mask = 0;
int is_equal () {
int j = 0;
mask = 0;
for (j=0; j<14; j++){
int n = c[j] - 'a';
if (mask & (1 << n))
return 0;
mask |= (1<<n);
}
return 1;
}
int main () {
int k = 0;
int j = 1;
char f;
c[15] = 0;
while (j < 5) {
c[k] = getchar();
k++;
j++;
}
while ((f = getchar()) != EOF) {
k %=14;
printf("%d %s f:%c\n",k,c,f);
if (is_equal()) break;
c[k] = f;
k++;
j++;
}
printf("%d\n", j-1);
}

View file

@ -3,6 +3,6 @@ all: bin $(programs)
bin:
mkdir bin
bin/% : %.c
gcc -o $@ $<
gcc -g -o $@ $<
clean :
rm $(programs)