修改文件结构。

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

47
POP/12/Exercise01.c Normal file
View File

@@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void readString(char** stringPtrPtr, int stringCount) {
char tempStringPtr[81] = {0};
int i = 0;
for (i = 0; i < stringCount; i++) {
scanf("%80s", tempStringPtr);//读入临时字符串
stringPtrPtr[i] = malloc(strlen(tempStringPtr) + 1);//创建一个和temp一样大的空间
strcpy(stringPtrPtr[i], tempStringPtr);//把temp 复制进新申请的地址里
}
}
void swap(char** a, char** b) {
char* tmp = *a;
*a = *b;
*b = tmp;
}
int main() {
int n = 0;
int i = 0;
char** stringPtrArrayPtr;//指向字符串指针数组的指针字符串指针数组的大小要根据N的数量确定有几个指针
int moved = 1;
scanf("%d", &n);
stringPtrArrayPtr = (char**) malloc(sizeof(int* ) * n);//根据N的大小决定要多少个字符串指针
readString(stringPtrArrayPtr, n);
while(moved) {
moved = 0;
for (i = 0; i < n - 1; i++) {
if (strcmp(stringPtrArrayPtr[i], stringPtrArrayPtr[i+1]) > 0) {
//若前面的比后面的大,就交换
moved = 1;
swap(&stringPtrArrayPtr[i], &stringPtrArrayPtr[i+1]);
}
}
}
for (i = 0; i < n; i++) {
printf("%s\n", stringPtrArrayPtr[i]);
}
return 0;
}

25
POP/12/Exercise02.c Normal file
View File

@@ -0,0 +1,25 @@
#include <stdio.h>
int main() {
int A[10][10] = {
{0,1,2,3,4,5,6,7,8,9},
{10,11,12,13,14,15,16,17,18,19},
{20,21,22,23,24,25,26,27,28,29},
{30,31,32,33,34,35,36,37,38,39},
{40,41,42,43,44,45,46,47,48,49},
{50,51,52,53,54,55,56,57,58,59},
{60,61,62,63,64,65,66,67,68,69},
{70,71,72,73,74,75,76,77,78,79},
{80,81,82,83,84,85,86,87,88,89},
{90,91,92,93,94,95,96,97,98,99}
};
int input = 0;
int i = 0;
int sum = 0;
scanf("%d", &input);
for (i = 0; i < 10; i++) {
sum += *(*(A + i) + ((i + input) % 10));
}
printf("%d\n", sum);
return 0;
}

39
POP/12/Exercise03.c Normal file
View File

@@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void output(char* start, char* end) {
char* ptr = start + 1;
for (;ptr < end; ptr++) {
printf("%c",*ptr);
}
printf("\n");
}
int main() {
char* inputStr = NULL;
char* startIndex = NULL;
char* p = NULL;
char startDelimiter, endDelimiter;
printf("转译符:");
scanf("%c", &startDelimiter);
printf("终止符:");
scanf(" %c", &endDelimiter);
getchar();
inputStr = malloc(141);
printf("输入文字:");
scanf("%[^\n]", inputStr);
p = inputStr;
while (p - inputStr < strlen(inputStr)) {
if (*p == startDelimiter) {
startIndex = p;
}
else if (*p == endDelimiter && startIndex != NULL) {
output(startIndex, p);
startIndex = NULL;
}
p++;
}
return 0;
}

79
POP/12/Optional01.c Normal file
View File

@@ -0,0 +1,79 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define UPRIGHT true
#define LEFTDOWN false
bool direction = UPRIGHT;
bool moveNext(int* i, int* j, int n) {
if (*i == n-1 && *j == n-1) {
return true;
}
if (direction == UPRIGHT) {
if (*i == 0) {
direction = LEFTDOWN;
if (*j == n-1) {
(*i)++;
}
else {
(*j)++;
}
}
else if (*j == n-1) {
direction = LEFTDOWN;
(*i)++;
}
else {
(*i)--;
(*j)++;
}
return false;
}
else {
if (*j == 0) {
direction = UPRIGHT;
if (*i == n-1) {
(*j)++;
}
else {
(*i)++;
}
}
else if (*i == n-1) {
direction = UPRIGHT;
(*j)++;
}
else {
(*i)++;
(*j)--;
}
return false;
}
}
int main() {
int *matrixPtr = NULL;
int n = 0;
int i = 0, j = 0;
scanf("%d", &n);
matrixPtr = malloc(n*n);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf("%d", matrixPtr + i*n + j);
}
}
i = 0;
j = 0;
while (true) {
printf("%d ", *(matrixPtr + i*n + j));
if (moveNext(&i, &j, n)) {
break;
}
}
printf("\n");
return 0;
}

9
POP/12/Optional02.c Normal file
View File

@@ -0,0 +1,9 @@
#include <stdio.h>
int main(int argc, char *argv[]) {
char **p;
for (p = argv; argc--; p++) {
printf("%c%s", **p, *p);
}
return 0;
}

24
POP/12/test.c Normal file
View File

@@ -0,0 +1,24 @@
#include <stdio.h>
int main() {
int a[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8},{9, 10, 11, 12}};
int *p = a[0];
int (*q)[4] = a;
int i = 0, j = 0;
for (i = 0; i < 3; i++) {
printf("%p: %d\n", p+i, *(p+i));
}
printf("-----\n");
for (i = 0; i < 12; i++) {
printf("%p: %d\n", p+i, *(p+i));
}
printf("-----\n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 4; j++) {
printf("%p: %d\n", (*(q+i)+j), *(*(q+i)+j));
}
}
printf("%ld", sizeof(char));
return 0;
}