Moved kattis from Uni repo

This commit is contained in:
2023-12-01 13:35:13 +01:00
parent 28a6b807a3
commit aaa2c123b8
164 changed files with 3008 additions and 0 deletions

View File

@ -0,0 +1 @@
iLnLnLeLb

View File

@ -0,0 +1 @@
arnarLLLBBun

View File

@ -0,0 +1 @@
password123

View File

@ -0,0 +1,60 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define MAX 1000000
int transform(char *src, int len, char *dst) {
// Traverse the string
int i = len;
int j = 0;
while (i > 0) {
// printf("%c\n", src[i]);
// If we encounter a backspace, we need to remove the last character
// from the destination string
if (src[i] == 'B') {
if (j > 0) {
j--;
}
} else if (src[i] == 'L') {
// If we encounter a left button, we have to move back once
if (j > 0) {
j--;
}
} else if (src[i] == 'R') {
// If we encounter a right button, we have to move forward once
if (j < len) {
j++;
}
}
else {
// Otherwise, we add the character to the destination string
dst[j] = src[i];
j++;
}
i--;
}
return j;
}
void printStr(char *s, int len) {
for (int i = 0; i < len; ++i) {
printf("%c", s[i]);
}
printf("\n");
}
int main(int argc, char **argv) {
char s[MAX];
scanf("%s", s);
int len = strlen(s);
printf("%d\n", len);
char corrected[MAX];
int newLen = transform(s, len, corrected);
printf("%d\n", newLen);
printStr(corrected, newLen);
return 0;
}

View File

@ -0,0 +1,58 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define MAX 1000000
int transform(char *src, int len, char *dst) {
// Traverse the string
int i = 0;
int j = 0;
while (i < len) {
// If we encounter a backspace, we need to remove the last character
// from the destination string
if (src[i] == 'B') {
if (j > 0) {
j--;
}
} else if (src[i] == 'L') {
// If we encounter a left button, we have to move back once
if (j > 0) {
j--;
}
} else if (src[i] == 'R') {
// If we encounter a right button, we have to move forward once
if (j < len) {
j++;
}
}
else {
// Otherwise, we add the character to the destination string
dst[j] = src[i];
j++;
}
i++;
}
return j;
}
void printStr(char *s, int len) {
for (int i = 0; i < len; ++i) {
printf("%c", s[i]);
}
printf("\n");
}
int main(int argc, char **argv) {
char s[MAX];
scanf("%s", s);
int len = strlen(s);
char corrected[MAX];
int newLen = transform(s, len, corrected);
printf("%d\n", newLen);
printStr(corrected, newLen);
return 0;
}

View File

@ -0,0 +1,22 @@
string = input()
string_list = []
cursor = 0
for char in string:
# If 'L' found in string, we move the cursor to the left
if char == 'L':
if cursor > 0:
cursor -= 1
# If 'R' found in string, we move the cursor to the right
elif char == 'R':
if cursor < len(string):
cursor += 1
# If 'B' found in string, we delete the character to the left of the cursor
elif char == 'B':
del string_list[cursor - 1]
cursor -= 1
# If any other character found in string, we insert it to the left of the cursor
else:
string_list.insert(cursor, char)
cursor += 1
# Print only the new string, without the initial one
print(''.join(string_list))

Binary file not shown.