1.1 字符切割
#include<stdio.h>
int main()
{
char ch[1000];
int i = 0, m = 0;
while ((ch[i] = getchar()) != '\n')
{
i++;
}
for (int j = 0; j < i; j++)
{
if (ch[j] == ' ' || (ch[j] >= 59 && ch[j] <=63 ) || (ch[j] >= 33 && ch[j] <= 47))
{
if (ch[j] == ' ' && ch[j - 1] == ' ')
{
continue;
}
else
{
m++;
}
}
}
printf("%d", m + 1);
return 0;
}
1.2 字符输出
#include<stdio.h>
int main()
{
char ch[1000];
int i = 0, m = 0;
while ((ch[i] = getchar()) != '\n')
{
i++;
}
for (int j = 0; j < i; j++)
{
if (ch[j] == ' ' || (ch[j] >= 59 && ch[j] <= 63) || (ch[j] >= 33 && ch[j] <= 47))
{
if (ch[j] == ' ' && ch[j - 1] == ' ')
{
continue;
}
else if ((ch[j] >= 59 && ch[j] <= 63) || (ch[j] >= 33 && ch[j] <= 47))
{
printf("\n%c", ch[j]);
continue;
}
else
{
printf("\n");
continue;
}
}
printf("%c", ch[j]);
}
return 0;
}
1.3 malloc 数组
int* MyArray(int length)
{
int* p;
if ((p = (int*)malloc(length * sizeof(int))) == NULL)
{
exit(1);
}
return p;
}
1.4 变长数组
2.1 神仙吧!!!
3.1 链表
#include<stdio.h>
#include<stdlib.h>
struct Date
{
int date;
struct Date* next;
};
struct Date* Add(struct Date* head, struct Date* list);
struct Date* Creat();
void Print_Date(struct Date* head);
int main()
{
struct Date* head, * p;
int date;
int size = sizeof(struct Date);
head = Creat();
Print_Date(head);
return 0;
}
struct Date* Creat()
{
struct Date* head, * p;
int date;
int size = sizeof(struct Date);
head = NULL;
scanf("%d", &date);
while (date != -1)
{
p = (struct Date*)malloc(size);
p->date = date;
head=Add(head, p);
scanf("%d", &date);
}
return head;
}
struct Date* Add(struct Date* head, struct Date* list)
{
struct Date* ptr = head;
struct Date* ptr1 = list;
if ( head== NULL)
{
head = ptr1;
head->next = NULL;
}
else
{
while (ptr!=NULL)
{
if (ptr->next == NULL)
{
ptr->next = ptr1;
ptr1->next = NULL;
}
ptr = ptr->next;
}
}
return head;
}
void Print_Date(Date* head)
{
struct Date* ptr;
ptr = head;
if (head == NULL)
{
printf("No date!\n");
return;
}
else
{
for (ptr; ptr != NULL; ptr = ptr->next)
{
printf("%d\n", ptr->date);
}
}
}
3.2 二叉树