RHZ'S BLOG | 个人分享

  • 首页
  • 笔记
  • 小日常
  • 音乐
  • 读书
  • 软件分享
YOLO
  1. 首页
  2. 笔记
  3. C/C++
  4. 正文

D-oj|在非递减有序表中删除多余重复元素 题目编号:1128

2022年11月15日 106点热度 1人点赞 0条评论

有序表数据元素为整型,输入非递减有序表中各元素(不用排序,输入即有序),将表中多余重复元素删除,并将表输出。

输入描述

  • 先输入非递减有序表中元素个数n;
  • 再输入n个整数元素,以空格隔开,注意,按有序方式输入;

输出描述

  • 输出删除多余重复数据元素后的有序表,元素之间以空格隔开

输入样例

10
1 1 1 2 2 2 2 3 3 4

输出样例

1 2 3 4 

代码:

#include <iostream>
using namespace std;
class seqList{
public:
    seqList(int a[],int num);
    char is_in(int b);
    void Print();
private:
    int data[20];
    int top,signs,num,nums;
};
void seqList::Print(){
    for(int i=0;i<nums;i++){
        cout<<data[i]<<" ";
    }

}
char seqList::is_in(int b){
    signs = top;
    while(signs!=-1){
        if(data[signs--]==b)return 'y';
    }
    if(signs==-1)return 'n';
}
seqList::seqList(int a[],int num){
    this->num=num;char sign;top=-1;nums=0;
    for(int i=0;i<num;i++){
        sign= is_in(a[i]);
        if(sign=='n'){
            data[++top]=a[i];
            nums++;
        }
    }
}

int main(){
    int a[20];
    int anum;
    cin>>anum;

    int data;
    for(int i=0;i<anum;i++){
        cin>>data;
        a[i]=data;
    }

    int number;char sign;
    seqList A=seqList(a,anum);

    A.Print();
}
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可
标签: 列表删除重复元素
最后更新:2022年11月15日

RHZ

即使单枪匹马,我亦勇敢无畏

点赞
< 上一篇
下一篇 >

文章评论

取消回复
归档
  • 2023年2月
  • 2022年12月
  • 2022年11月
  • 2022年10月
  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2022年3月
  • 2022年2月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年8月
  • 2021年7月

COPYRIGHT © 2022 RHZ的博客. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

渝ICP备2022008933号-1