顺序表应用1:多余元素删除之移位算法

Time Limit: 1000 ms Memory Limit: 650 KiB

Submit Statistic Discuss

Problem Description

一个长度不超过10000数据的顺序表,可能存在着一些值相同的“多余”数据元素(类型为整型),编写一个程序将“多余”的数据元素从顺序表中删除,使该表由一个“非纯表”(值相同的元素在表中可能有多个)变成一个“纯表”(值相同的元素在表中只保留第一个)。
要求:
       1、必须先定义线性表的结构与操作函数,在主函数中借助该定义与操作函数调用实现问题功能;
       2、本题的目标是熟悉顺序表的移位算法,因此题目必须要用元素的移位实现删除;

Input

第一行输入整数n,代表下面有n行输入;
之后输入n行,每行先输入整数m,之后输入m个数据,代表对应顺序表的每个元素。

Output

输出有n行,为每个顺序表删除多余元素后的结果

Sample Input

4
5 6 9 6 8 9
3 5 5 5
5 9 8 7 6 5
10 1 2 3 4 5 5 4 2 1 3

Sample Output

6 9 8
5
9 8 7 6 5
1 2 3 4 5

比较简单;;;;

#include <stdio.h>
#include <stdlib.h> int List[11999];
int i,j,k; void createlist ( int * List, int n )
{
for( i=0; i<n; i++ )
{
scanf("%d", &List[i]);
}
} void del ( int * List, int n )
{
for ( i=0; i<n; i++ )
{
for( j=i+1; j<n; j++ )
{
if( List[j] == List[i] )
{
n--; //删掉一个数;
for( k=j; k<n; k++ )
{
List[k] = List[k+1];
}
j--; //为下一次循环保证从新数开始;
}
}
}
for( i=0; i<n-1; i++) //写在函数里而不写在main函数里是因为此n非彼n;
printf("%d ", List[i]);
printf("%d\n", List[i]);
} int main()
{
int n, m;
scanf("%d", &n);
while( n-- )
{
scanf("%d", &m);
createlist( List, m );
del( List, m );
//输出部分写在这是不行的;此n非彼n;
}
return 0;
}

SDUT OJ 顺序表应用1:多余元素删除之移位算法的更多相关文章

  1. SDUT OJ 顺序表应用4:元素位置互换之逆置算法

    顺序表应用4:元素位置互换之逆置算法 Time Limit: 10 ms Memory Limit: 570 KiB Submit Statistic Discuss Problem Descript ...

  2. SDUT OJ 顺序表应用3:元素位置互换之移位算法

    顺序表应用3:元素位置互换之移位算法 Time Limit: 1000 ms Memory Limit: 570 KiB Submit Statistic Discuss Problem Descri ...

  3. 顺序表应用1:多余元素删除之移位算法(SDUT 3324)

    Problem Description 一个长度不超过10000数据的顺序表,可能存在着一些值相同的"多余"数据元素(类型为整型),编写一个程序将"多余"的数据 ...

  4. SDUT OJ 顺序表应用2:多余元素删除之建表算法

    顺序表应用2:多余元素删除之建表算法 Time Limit: 3 ms Memory Limit: 600 KiB Submit Statistic Discuss Problem Descripti ...

  5. SDUT OJ 顺序表应用6:有序顺序表查询

    顺序表应用6:有序顺序表查询 Time Limit: 1000 ms Memory Limit: 4096 KiB Submit Statistic Discuss Problem Descripti ...

  6. SDUT OJ 顺序表应用5:有序顺序表归并

    顺序表应用5:有序顺序表归并 Time Limit: 100 ms Memory Limit: 880 KiB Submit Statistic Discuss Problem Description ...

  7. 顺序表应用3:元素位置互换之移位算法(SDUT 3326)

    题解:用一个for,循环m次,每次都把最前面的放到最后面,就可以了. #include <stdio.h> #include <stdlib.h> #include <s ...

  8. 设顺序表中的数据元素递增有序,试着写一算法,将x插入到顺序表上的适当位置上,以保持该表的有序性。

    原创,转载请注明出处.https://www.cnblogs.com/yangf428/p/11254370.html 天勤例题[2-1]: 设顺序表va中的数据元素递增有序.试写一算法,将x插入到顺 ...

  9. 顺序表应用2:多余元素删除之建表算法(SDUT 3325)

    题解: 每次询问一遍,如果已经存在就不用插入表中了. #include <stdio.h> #include <stdlib.h> #include <string.h& ...

随机推荐

  1. Delphi IOS 上架

    http://docwiki.embarcadero.com/RADStudio/Seattle/en/IOS_Mobile_Application_Development http://docwik ...

  2. clock函数返回负值~ (转)

    使用clock() 函数来进行计时,时不时的返回一个很大的负数,怎么检查也检查不出错误,现在找出错误原因,给大家分享一下. 来源网页:http://kebe-jea.blogbus.com/logs/ ...

  3. java中FILE类常用API介绍

  4. Oracle-11g 中当执行 DBMS_STATS 时,因数据泵外部表文件缺失 Alert Log 告警 "ORA-20011、ORA-29913" 以及 "KUP-XXXXX"错误

    :first-child { margin-top: 0; } blockquote > :last-child { margin-bottom: 0; } img { border: 0; m ...

  5. Docker学习笔记_安装和使用Zookeeper

    一.准备 1.宿主机OS:Win10 64位 2.虚拟机OS:Ubuntu18.04 3.账号:docker 二.安装 1.搜索镜像                                  ...

  6. 下载Redis

    1.下载当前Redis 官网:https://redis.io/ 当前稳定版本是4.0.11,如下图,点Download it下面的链接进行下载 2.下载历史版本的Resis 网址: http://d ...

  7. 智能IC卡中的文件系统

    1.文件系统是COS的重要模块之一,它负责组织.管理.维护IC卡内存储的所有数据. 文件系统的设计和实现既是COS系统中最灵活.最有个性的部分,也是对系统整体结构影响最大的模块之一. 2.在IC卡内, ...

  8. datagrid 自定义 pager

    $(document).ready(function(){ var p = $('.easyui-datagrid').datagrid('getPager'); $(p).pagination({ ...

  9. Haar-like feature和Haar wavelet

    Haar-like features are digital image features used in object recognition. They owe their name to the ...

  10. 【转】Android自定义控件(二)——有弹性的ScrollView

    原文地址:http://blog.csdn.net/a105865708/article/details/17784041 实现了当手指滑动到ScrollView的顶部.底部时, 可以继续的向上.向下 ...