当前位置:首页 > C语言程序设计下mooc答案
P->next = (LinkList)malloc(sizeof(List)); P = P->next;
scanf(\ if(c == '\\n') break; }
P->next = NULL; return L; }
LinkList MergeLinkList(LinkList L1,LinkList L2) {
LinkList P1 = L1->next, P2 = L2->next;
LinkList L = (LinkList)malloc(sizeof(List)),P; P = L;
while(P1 && P2) {
P->next = (LinkList)malloc(sizeof(List)); P = P->next;
if(P1->data > P2->data) {
P->data = P2->data; P2 = P2->next; }
else if(P1->data < P2->data) {
P->data = P1->data; P1 = P1->next; } else {
P->data = P1->data; P1 = P1->next; P2 = P2->next; } }
while(P1) {
P->next = (LinkList)malloc(sizeof(List)); P = P->next;
P->data = P1->data; P1 = P1->next; }
while(P2) {
P->next = (LinkList)malloc(sizeof(List));
P = P->next;
P->data = P2->data; P2 = P2->next; }
P->next = 0; return L; }
void ShowList(LinkList L) {
LinkList P = L->next; while(P->next) {
printf(\ P = P->next; }
printf(\}
int main() {
LinkList L1,L2,L3; L1 = CreateLinkList(); L2 = CreateLinkList(); L3 = MergeLinkList(L1,L2); ShowList(L3); return 0; }
第九周编程作业
1、解析字符串(15分) 题目内容:
输入一个字符串,要求将其中的字母‘n’理解为回车符号’\\n’,模拟文件缓冲区读取的数据,并按替换后的数据流解析出其中包括的字符串。(即通过'n'分割两个字符串) 输入格式:
一个字符串 输出格式:
其中包括的字符串 输入样例: abcnde[回车] 输出样例: abc[回车] de[回车]
时间限制:500ms内存限制:32000kb Code:
#include
int i,j,k; char a[100]; gets(a); k=strlen(a);
printf(\ for(i=1;i if(a[i]=='n') { if(a[i-1]!='n') printf(\ } else printf(\ } for(i=i+1;i 2、字符串的输入与反向显示(15分) 题目内容: 请用标准设备文件的方式完成字符串的输入与反向显示。 输入格式: 字符串 输出格式: 字符串 输入样例: abc[回车] 输出样例: cba[回车] 时间限制:500ms内存限制:32000kb Code: #include void reverse(char str[],int start,int end) { char t; if(end>=strlen(str)) reverse(str,start,end-1); else if(start t=str[start]; str[start]=str[end]; str[end]=t; reverse(str,start+1,end-1); } } int main( ) { char str[100]; int start, end; gets(str); start=0;end=strlen(str); reverse(str,start,end); printf(\ return 0; } 第十周编程作业 1、基本四则运算表达式(15分) 题目内容: 请结合C语言语法知识以及对编译过程的理解,完成一个仅含一个运算符的基本四则运算表达式字符串的计算。 输入格式: 基本四则运算表达式字符串 输出格式: 运算结果 输入样例: 1+2 输出样例: 3 时间限制:500ms内存限制:32000kb Code: #include char op; int i,a,b; scanf(\ switch(op) { case '+':printf(\ case '-':printf(\ case '*':printf(\ case '/':printf(\
共分享92篇相关文档