ytu 2228 判断链表
来源:互联网 发布:windows邮件客户端 编辑:程序博客网 时间:2024/06/11 21:12
题目链接:http://202.194.119.110/problem.php?id=2228
代码:
#include<stdio.h>#include<malloc.h>typedef struct node node;struct node{ int num; node *next;};int main(){ int m,n; node *list1 = (node*)malloc(sizeof(node)); node *list2 = (node*)malloc(sizeof(node)); list1->next = NULL; list2->next = NULL; int count = 0; int fubenn = 0;; node *current = NULL; scanf("%d",&m); while(m--)//创建较长的链表 { current = (node*)malloc(sizeof(node)); scanf("%d",¤t->num); current->next = list1->next; list1->next = current; } scanf("%d",&n); fubenn = n; while(n--)//创建较短的链表 { current = (node*)malloc(sizeof(node)); scanf("%d",¤t->num); current->next = list2->next; list2->next = current; } node *temp = NULL; node *fal = NULL; node *fuben = list2; while(list2->next)//枚举,判断短序列是否是长序列的子序列 { temp = list1; while(temp->next) { if(temp->next->num == list2->next->num) { count++; fal = temp->next;//扫描到的节点就释放掉 temp->next = fal->next; free(fal); break; } temp->next = temp->next->next; } current = list2->next;//扫描过的节点就释放掉 list2->next = current->next; free(current); } free(fuben); current = list1->next; free(list1); while(current)//销毁链表,释放剩余的空间 { list1 = current; current = current->next; free(list1); } current = list1 = list2 = fuben = fal = temp = NULL; if(count == fubenn) printf("1\n"); else printf("0\n"); return 0;}
智力有限,想不出太好的方法。虽然ac了,不过在 判断短序列是否是长序列的子序列的那个循环 内还是有些问题。水平有限,只能发现那里有问题,如果哪位大神发现了具体的问题,求告知。其实感觉我的逻辑也是有些问题。
0 0
- ytu 2228 判断链表
- ytu 1072 链表合并
- ytu 2202 合并链表
- YTU.2683: 英文字母的判断
- YTU 2209: 建立链表(线性表)
- YTU 2620: B 链表操作
- ytu 2213 链表的拆分
- YTU 2802: 判断字符串是否为回文
- [YTU]_2803( 判断字符串是否为回文)
- YTU 2990: 链表的基本运算(线性表)
- YTU 2991: 链表节点逆置(线性表)
- YTU.3174: 链表基本操作---指定结点删除
- YTU 3001: 判断操作是否合法(栈和队列)
- YTU 2430: C语言习题 链表建立,插入,删除,输出
- YTU 3008: 链串的基本运算
- YTU 2203: 最小节点(线性表)
- YTU 2715: 函数---判断某年某月某日是这一年中的第几天
- [YTU](2278)判断是否是子串(串) ---字符串匹配(串)
- 2016.2.27模拟比赛总结
- [HNOI2008] [BZOJ1009] GT考试
- 第六章:Linux的文件权限
- NDK开发环境的搭建
- 智能硬件X1000平台代码下载编译方法
- ytu 2228 判断链表
- [leetcode Q26] Remove Duplicates from Sorted Array
- 2015年10月最新大神班小码哥视频
- jsp编译、执行过程
- 2015年10月最新大神班小码哥视频
- hbase源码打包
- 最新大神班小码哥视频
- Android ContentProvider和Uri详解
- centos的nginx+https配置