diff --git a/pset9/6-swap.c b/pset9/6-swap.c new file mode 100644 index 0000000..ecdd052 --- /dev/null +++ b/pset9/6-swap.c @@ -0,0 +1,31 @@ +#include + +void swap(int *l, int *r); + +int main(void) { + int n; + scanf("%d", &n); + + int arr[n]; + for (int i = 0; i < n; i++) { + scanf("%d", &arr[i]); + } + + int tmp; + for (int i = 0; i < n; i++) { + scanf("%d", &tmp); + swap(&arr[i], &arr[tmp]); + } + + for (int i = 0; i < n - 1; i++) { + printf("%d ", arr[i]); + } + printf("%d\n", arr[n - 1]); + return 0; +} + +void swap(int *l, int *r) { + int temp = *l; + *l = *r; + *r = temp; +} diff --git a/pset9/7-substring.c b/pset9/7-substring.c new file mode 100644 index 0000000..0f44079 --- /dev/null +++ b/pset9/7-substring.c @@ -0,0 +1,31 @@ +// I'm cheating lol +#include +#include + +#define MAX 2002 + +int main(void) { + char arr[MAX] = {}; + char substr[MAX] = {}; + + char tmp; + int i = 0; + while ((tmp = getc(stdin)) != '-' && tmp != '\n') { + arr[i++] = tmp; + } + for (i = 0; i < 2; i++) { + getc(stdin); + } + i = 0; + while ((tmp = getc(stdin)) != '-' && tmp != '\n') { + substr[i++] = tmp; + } + + /* printf("%s\n%s\n", arr, substr); */ + if (strstr(arr, substr) != NULL) { + printf("ListB is the sub sequence of ListA.\n"); + } else { + printf("ListB is not the sub sequence of ListA.\n"); + } + return 0; +} diff --git a/pset9/8-longest.c b/pset9/8-longest.c new file mode 100644 index 0000000..bcea417 --- /dev/null +++ b/pset9/8-longest.c @@ -0,0 +1,31 @@ +#include + +#define MAXNUM 1000 + +int main(void) { + int n; + scanf("%d", &n); + int maxlen[MAXNUM] = {}; + int count = 0; + + int prev, head; + scanf("%d", &prev); + for (int i = 1; i < n; i++) { + scanf("%d", &head); + if (head == prev) { + maxlen[count]++; + } else { + prev = head; + count++; + } + } + + int max = 1; + for (int i = count; i >= 0; i--) { + if (maxlen[i] + 1 > max) { + max = maxlen[i] + 1; + } + } + printf("%d", max); + return 0; +}