修改文件结构。

This commit is contained in:
unlockable
2023-02-21 10:56:54 +08:00
parent a64cfdd9f3
commit 40182871f4
83 changed files with 0 additions and 0 deletions

62
POP/11/Exercise01.c Normal file
View File

@@ -0,0 +1,62 @@
#include <stdio.h>
void sort(int *start, int length);
void swap(int *a, int *b);
int main() {
int a[10], b[10], result[20];
int *aIndex = a, *bIndex = b, *resultIndex = result;
for (aIndex = a; aIndex < a+10; aIndex++) {
scanf("%d", aIndex);
}
for (bIndex = b; bIndex < b + 10; bIndex++) {
scanf("%d", bIndex);
}
aIndex = a;
bIndex = b;
sort(a, 10);
sort(b, 10);
aIndex = a;
bIndex = b;
while (resultIndex < result + 20) {
if (*aIndex <= *bIndex || bIndex > b + 9) {
// aIndex不能越界要改
*resultIndex = *aIndex;
aIndex++;
}
else if (*bIndex < *aIndex || aIndex > a + 9) {
*resultIndex = *bIndex;
bIndex++;
}
resultIndex++;
}
resultIndex = result;
while (resultIndex < result+20) {
printf("%d ", *resultIndex);
resultIndex++;
}
printf("\n");
return 0;
}
void sort(int *start, int length) {
int moved = 1;
int *index = start;
while (moved) {
moved = 0;
index = start;
while (index < start + length - 1) {
if ( *index > *(index + 1)) {
moved = 1;
swap(index, index+1);
}
index++;
}
}
}
void swap(int *a, int *b) {
int tmp;
tmp = *a;
*a = *b;
*b = tmp;
}

44
POP/11/Exercise03.c Normal file
View File

@@ -0,0 +1,44 @@
#include <stdio.h>
#include <stdbool.h>
int findIndex(int a[], int num) {
int i = 0;
for (i = 0; i < 10; i++) {
if (a[i] == num) {
return i;
}
}
return -1;
}
int main() {
int a[10] = {0};
int *pa[10] = {0};
int *tmp;
int i = 0;
bool moved = true;
for(i = 0; i < 10; i++) {
pa[i] = a+i;
scanf("%d", a+i);
}
while(moved) {
moved = false;
for (i = 0; i < 9; i++) {
if (*pa[i] > *pa[i+1]) {
tmp = pa[i];
pa[i] = pa[i+1];
pa[i+1] = tmp;
moved = true;
}
}
}
for (i = 0; i < 10; i++) {
printf("%d ", *pa[i]);
}
printf("\n");
for (i = 0; i < 10; i++) {
printf("%d ", findIndex(a, *pa[i]));
}
printf("\n");
return 0;
}

32
POP/11/Exercise2.c Normal file
View File

@@ -0,0 +1,32 @@
#include <stdio.h>
#include <stdbool.h>
#define INCIRCLE false
#define OUTCIRCLE true
void del(int *p, int m) {
int nowPos = 0, count = 0, outCount = 0;
for (outCount = 0; outCount < m - 1; outCount++) {
count = 0;
while (count < 3) {
if ( *(p + nowPos) == INCIRCLE) {
count++;
}
nowPos = (nowPos + 1) % m;
}
*(p + ((nowPos + m - 1) % m)) = OUTCIRCLE;
}
for (;;nowPos = (nowPos + 1) % m) {
if (*(p+nowPos) == INCIRCLE) {
printf("%d\n", nowPos + 1);
break;
}
}
}
int main() {
int num[50] = {0};
int n = 0;
scanf("%d", &n);
del(num, n);
return 0;
}

13
POP/11/Optional01.c Normal file
View File

@@ -0,0 +1,13 @@
#include <stdio.h>
char *a = "HAPPYNEWYEAR";
char b[] = "happynewyear";
int main() {
int i = 8;
printf("%c%c%s%s\n", *a, b[0], b+5, &a[5]);
while(*(a+i)) {
putchar(*(a+(i++)));
}
return 0;
}

53
POP/11/Optional02.c Normal file
View File

@@ -0,0 +1,53 @@
#include <stdio.h>
void calcNext(int lastResult) {
if (lastResult == 6174)
{
return;
}
}
int main() {
int digits[10] = {0};
int maxComb, minComb;
int nowChecking;
int curDigit = 0;
int i = 0, j = 0;
scanf("%d", &nowChecking);
while (nowChecking > 0) {
curDigit = nowChecking % 10;
if (digits[curDigit] > 0) {
printf("error");
return 0;
}
else {
digits[curDigit] = 1;
nowChecking /= 10;
}
}
while (nowChecking != 6174) {
maxComb = 0;
minComb = 0;
for (i = 0; i < 10; i++) {
for (j = 0; j < digits[i]; j++) {
minComb = minComb * 10 + i;
}
}
for (i = 9; i >= 0; i--) {
for (j = 0; j < digits[i]; j++) {
maxComb = maxComb * 10 + i;
}
}
nowChecking = maxComb - minComb;
printf("%d - %d = %d\n", maxComb, minComb, nowChecking);
for (i = 0; i < 10; i++) {
digits[i] = 0;
}
while (nowChecking > 0) {
digits[nowChecking % 10]++;
nowChecking /= 10;
}
nowChecking = maxComb - minComb;
}
return 0;
}