【题目内容】
一个四则运算题目信息包括年级、难度和算式,请从键盘输入一组题目存入链表中。
【输入形式】
数组大小n,题目信息
【输出形式】
打印所有题目
【测试用例1】
输入:
2
1 0 3+2
1 1 10+15
输出:
1 0 3+2
1 1 10+15
#include <stdio.h>
#include <string.h>
struct node
{
char s[50];
struct node *pNext;
};
void main()
{
struct node *pHead = NULL, *pEnd = NULL, *pNode = NULL;
int i = 1,n;
char str[50],ch;
scanf("%d",&n);
for(i=0; i<=n; i++)
{
pNode = (struct node *)malloc(sizeof(struct node));
if(pNode != NULL)
{
gets(str);
strcpy(pNode -> s,str);
//puts(pNode -> s);
pNode -> pNext = NULL;
if(pHead == NULL)
{
pHead = pNode;
pEnd = pNode;
}
else
{
pEnd -> pNext = pNode;
pEnd = pNode;
}//end of if(pHead == NULL)
}//end of if(pNode != NULL)
}
pNode = pHead;
while(pNode != NULL)
{
printf("%s\n", pNode -> s);
pHead = pNode;
pNode = pNode -> pNext;
free(pHead);
}
printf("\n");
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!