add 6 to 8
This commit is contained in:
parent
59dbc4ce6a
commit
92c01818fd
31
pset9/6-swap.c
Normal file
31
pset9/6-swap.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
31
pset9/7-substring.c
Normal file
31
pset9/7-substring.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
// I'm cheating lol
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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;
|
||||
}
|
31
pset9/8-longest.c
Normal file
31
pset9/8-longest.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#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;
|
||||
}
|
Loading…
Reference in a new issue