题目描述:
Petya has an array a consisting of n integers. He wants to remove duplicate (equal) elements.
Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.
input
The first line contains a single integer n (1≤n≤50) — the number of elements in Petya’s array.
The following line contains a sequence a1,a2,…,an (1≤ai≤1000) — the Petya’s array.
output
In the first line print integer x — the number of elements which will be left in Petya’s array after he removed the duplicates.
In the second line print x integers separated with a space — Petya’s array after he removed the duplicates. For each unique element only the rightmost entry should be left.

题意:输入一串数字,但是要去除重复的数字,并且在相同的数字的时候要保留最右边的那个
注意点:输出格式要求有点严格,必须要留下最右边的那个重复数字
不多说直接上代码

#include <iostream>
#include <cstdio>
#include <map>
#include <cstring>using namespace std;
int main () {int n;int A[60];bool vis[60];//标记每个数字是否被删除memset(vis,1,sizeof(vis));cin >> n;for (int i = 1;i <= n;i++) cin >> A[i];for (int i = 1;i <= n;i++) for (int j = i+1;j <= n ;j++) if(A[i] == A[j])//查找相同的数字,然后将左边的数字标记为已经删除vis[i] = 0;int ans = 0;//进行循环查找有多少个没被删除的数字for(int i = 1;i <= n;i++)if(vis[i])ans++;cout << ans << "\n";bool f = 1;for (int i = 1;i <= n;i++) {if(vis[i]&&f) {//输出每个没被删除的数字cout << A[i];f = 0;}else if(vis[i]&&!f)cout << " " << A[i];}cout << "\n";return 0;
}

Remove Duplicate相关推荐

  1. LeetCode 316. Remove Duplicate Letters--贪心--Java,C++,Python解法

    题目地址:Number of Longest Increasing Subsequence - LeetCode 做这道题目前建议先做:Longest Increasing Subsequence - ...

  2. [leetcode] remove duplicate letters

    用时4ms,内存1M (好高啊魂淡 思路: 先找出在"仍保留原字符串中所有字母种类,开头字母最小"的后缀子字符串.i.e.如果前面遍历到的字母在后面仍有出现则忽略掉,继续找最小首字 ...

  3. LeetCode 316. Remove Duplicate Letters

    (自己开发的博客,欢迎访问)https://www.weiboke.online 316. Remove Duplicate Letters Given a string which contains ...

  4. LeetCode 316 Remove Duplicate Letters(删除重复字符)

    问题:给出一个字符串,要求删除重复字符,字典序是最小并且保持字符的相对位置. 思路: 方法一,使用递归算法,在出现只出现一次的前缀字符串中确定最小字符,然后在剩下的子串中递归. 方法二,使用栈做,先记 ...

  5. 316. Remove Duplicate Letters 去除重复字母

    给你一个字符串 s ,请你去除字符串中重复的字母,使得每个字母只出现一次.需保证 返回结果的字典序最小(要求不能打乱其他字符的相对位置). 注意:该题与 1081 https://leetcode-c ...

  6. leetcode 316. Remove Duplicate Letters | 316. 去除重复字母(单调栈解法)

    题目 https://leetcode.com/problems/remove-duplicate-letters 题解 关于什么是"字典序" 字典序,换成数字更好理解一点 a:1 ...

  7. 316 Remove Duplicate Letters 去除重复字母

    给定一个仅包含小写字母的字符串,去除重复的字母使得所有字母出现且仅出现一次.你必须保证返回结果是所有可能结果中的以字典排序的最短结果. 例如: 给定 "bcabc" 返回 &quo ...

  8. 从JS数组中删除重复的值[duplicate]

    本文翻译自:Remove duplicate values from JS array [duplicate] This question already has answers here : 这个问 ...

  9. CloudCompare 的简单的使用说明

    File open:打开 save:保存 Global Shift settings:设置最大绝对坐标,最大实体对角线 Primitive Factory:对点云进行原始加工,改变原始点云的形状 3D ...

最新文章

  1. 架构中的一切都是权衡
  2. linux基本命令iscsiadm,tgtadm和iscsiadm命令的用法
  3. 自学python爬虫要多久-Python爬虫要学多久,给初学编程者的建议
  4. HDOJ 1069 Monkey and Banana
  5. 2021甘肃高考艺考成绩查询,2021甘肃艺术统考/联考成绩查询时间及入口
  6. 想写总结,却变成了胡诌。。。
  7. 众所周知,YouTube是个学习网站
  8. Java回顾之多线程同步
  9. 机智的ensemble
  10. 4004-基于邻接矩阵的新顶点的增加(C++,附思路)
  11. javascript 时间类型 Date
  12. 操作系统 第五章 IO管理
  13. 全国高等院校英语能力大赛模拟题
  14. 了解HTML CSS格式化排版 文字排版
  15. Centos 下tomcat环境搭建
  16. 自动聊天机器人项目班 [一门课搞定聊天机器人]
  17. 联想拯救者笔记本电脑Fn键失效,Fn功能相反,开关FnLock
  18. 浅谈~区块链的现状与未来!
  19. 定义一个长方形类,求周长和面积--学习笔记--16
  20. centos下安装xcrysden出现的问题

热门文章

  1. 让人和猪都很感动的广告
  2. php mine类型大全
  3. 智慧城市井盖运营商业方案
  4. 重磅!悉尼科大ReLER实验室13篇论文入选CVPR 2021
  5. matlab 求解体积,matlab如何计算多面体体积
  6. IE卫士v1.02 --- 一款完全免费的IE修复工具
  7. 计算机基础(笔记)——计算机网络(无线网络和移动网络)
  8. zabbix搭建详细全过程,以及遇到的问题
  9. 发布炸弹超人游戏(C语言游戏源码)
  10. string.find()函数用法