顺序表应用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. MySQL: [Err] 1093 - You can't specify target table 'bk' for update in FROM clause

    错误的意思说,不能先select出同一表中的某些值,再update这个表(在同一语句中). 例如下面这个sql: delete from tbl where id in (        select ...

  2. Python基础学习三 字符串

    字符串方法 slit = ['a', 'b', 'c', 'd', 'f', 'g'] s2='hhhhhhhhhh' tu = (1,2,3,4,5) d={'name':'nnn','age':1 ...

  3. mysql 添加字段、删除字段、调整字段顺序

    用过MySQL的朋友,可能都在使用phpMyAdmin,我从2003年开始使用,感觉那东西适合远程mysql管理,并 不适合单机.单数据库的管理操作,特别是开发使用. 给家推荐一个软件管理mysql数 ...

  4. 【284】◀▶ arcpy.da & arcpy 数据访问模块

    使用游标访问数据 数据访问模块 (arcpy.da) 参考: ArcGIS Python编程案例(9)-ArcPy数据访问模块 读取几何 写入几何 使用 Python 指定查询 01   da.Sea ...

  5. [android] setOnTouchEvent 设置返回值为true 和 false的区别

    今天在做自定义的可选文本的 TextView 类时,用到了 View 类的 setOnTouchListener(OnTouchListener l)事件监听,在构造 OnTouchListener ...

  6. Flask+gevent 异步 WEB 架构

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

  7. MRPT - Mobile Robot Programming Toolkit

    1. https://www.mrpt.org/Building_and_Installing_Instructions#1_Prerequisites P1. error C2371: “int32 ...

  8. launchpad, jira, github

    一.简介 http://segmentfault.com/q/1010000000165115

  9. 符合mvc思维的分页思想

    .Model Student.cs namespace WebApplication14.Models { public class Student { public int Id { get; se ...

  10. DataTable 设置primarykey 后进行 Merge操作

    1.先查看概念 可以看highplayer博客 http://blog.csdn.net/highplayer/article/details/6613817 2. protected void st ...