数据结构上机测试1:顺序表的应用
2014-02-15 16:52
239 查看
数据结构上机测试1:顺序表的应用
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
在长度为n(n<1000)的顺序表中可能存在着一些值相同的“多余”数据元素(类型为整型),编写一个程序将“多余”的数据元素从顺序表中删除,使该表由一个“非纯表”(值相同的元素在表中可能有多个)变成一个“纯表”(值相同的元素在表中只能有一个)。输入
第一行输入表的长度n;第二行依次输入顺序表初始存放的n个元素值。
输出
第一行输出完成多余元素删除以后顺序表的元素个数;第二行依次输出完成删除后的顺序表元素。
示例输入
12 5 2 5 3 3 4 2 5 7 5 4 3
示例输出
5 5 2 3 4 7
#include <stdio.h> #include <stdlib.h> struct node { int data; struct node *next; }; int main() { int n,m=0,i; struct node *head,*r,*p,*tail,*q; head=(struct node*)malloc(sizeof(struct node)); head->next=NULL; tail=head; scanf("%d",&n); for(i=0;i<n;i++) { p=(struct node*)malloc(sizeof(struct node)); scanf("%d",&p->data); tail->next=p; tail=p; } p->next=NULL; for(p=head->next;p;p=p->next) for(q=p;q->next;) { if(q->next->data==p->data) { r=q->next; q->next=r->next; free(r); m++; } else q=q->next; } printf("%d\n",n-m); p=head->next; while(p) { if(p->next)printf("%d ",p->data); else printf("%d",p->data); p=p->next; } return 0; }
相关文章推荐
- 数据结构上机测试1:顺序表的应用
- 【1130】数据结构上机测试1:顺序表的应用 (链表的建立于重复元素删除) SDUT
- 数据结构上机测试1:顺序表的应用
- 【1130】数据结构上机测试1:顺序表的应用 (两种方法) SDUT
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 寒假第二天--线性表--数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用 7.24补
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 2016暑假集训7.27 链表 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 1130-数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 1489 求二叉树的先序遍历 1291 数据结构上机测试4.1:二叉树的遍历与应用1【二叉树遍历顺序转换】
- 数据结构上机测试1:顺序表的应用
- 1130 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用
- 数据结构上机测试1:顺序表的应用