Duplicate Removal
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1745   Accepted: 1213

Description

The company Al's Chocolate Mangos has a web site where visitors can guess how many chocolate covered mangos are in a virtual jar. Visitors type in a guess between 1 and 99 and then click on a "Submit" button. Unfortunately, the response time from the server
is often long, and visitors get impatient and click "Submit" several times in a row. This generates many duplicate requests. 

Your task is to write a program to assist the staff at ACM in filtering out these duplicate requests.

Input

The input consists of a series of lines, one for each web session. The first integer on a line is N, 0 < N ≤ 25, which is the number of guesses on this line. These guesses are all between 1 and 99, inclusive. The value N = 0 indicates the end of all the input.

Output

For each input data set, output a single line with the guesses in the original order, but with consecutive duplicates removed. Conclude each output line with the dollar sign character '$'. Note that there is a single space between the last integer and the dollar
sign.

Sample Input

5 1 22 22 22 3
4 98 76 20 76
6 19 19 35 86 86 86
1 7
0

Sample Output

1 22 3 $
98 76 20 76 $
19 35 86 $
7 $

题意是将相近的重复元素删除。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <set>
#pragma warning(disable:4996)
using namespace std; vector<int>a;
int num; int main()
{
int i,temp;
while(cin>>num)
{
if(num==0)
break;
a.clear();
for(i=1;i<=num;i++)
{
cin>>temp;
a.push_back(temp);
} vector<int>::iterator iter =unique(a.begin(),a.end());
a.erase(iter,a.end());
for(i=0;i<a.size();i++)
{
cout<<a[i]<<" ";
}
cout<<"$"<<endl;
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 3916:Duplicate Removal 将相近的重复元素删除的更多相关文章

  1. poj 1743 Musical Theme(最长重复子串 后缀数组)

    poj 1743 Musical Theme(最长重复子串 后缀数组) 有N(1 <= N <=20000)个音符的序列来表示一首乐曲,每个音符都是1..88范围内的整数,现在要找一个重复 ...

  2. 大型网站技术架构(四)--核心架构要素 开启mac上印象笔记的代码块 大型网站技术架构(三)--架构模式 JDK8 stream toMap() java.lang.IllegalStateException: Duplicate key异常解决(key重复)

    大型网站技术架构(四)--核心架构要素   作者:13GitHub:https://github.com/ZHENFENG13版权声明:本文为原创文章,未经允许不得转载.此篇已收录至<大型网站技 ...

  3. [LeetCode] 217. Contains Duplicate 包含重复元素

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  4. [LeetCode] 219. Contains Duplicate II 包含重复元素 II

    Given an array of integers and an integer k, find out whether there are two distinct indices i and j ...

  5. [LeetCode] 220. Contains Duplicate III 包含重复元素 III

    Given an array of integers, find out whether there are two distinct indices i and j in the array suc ...

  6. [Swift]LeetCode217. 存在重复元素 | Contains Duplicate

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  7. leetcode-219-Contains Duplicate II(使用set来判断长度为k+1的闭区间中有没有重复元素)

    题目描述: Given an array of integers and an integer k, find out whether there are two distinct indices i ...

  8. leetcode-217-Contains Duplicate(使用排序来判断整个数组有没有重复元素)

    题目描述: Given an array of integers, find if the array contains any duplicates. Your function should re ...

  9. LeetCode 217:存在重复元素 Contains Duplicate

    题目: 给定一个整数数组,判断是否存在重复元素. Given an array of integers, find if the array contains any duplicates. 如果任何 ...

随机推荐

  1. myBatis mapper接口方法重载问题

    在mybatis框架中,写dao层的mapper接口时,是不可以进行方法的重载的,下面是截图证明:   当mapper接口中有方法的重载时,会出现异常,   这是mapper接口中定义的两个方法,进行 ...

  2. Linux centosVMware apache 限定某个目录禁止解析php、限制user_agent、php相关配置

    一.限定某个目录禁止解析php 核心配置文件内容 vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf 先创建.编辑一个php 配置 vim /u ...

  3. Ubuntu18.04-MySQL8.0-表名大小写敏感-远程连接

    1.卸载 停止服务 sudo service mysql stop 删除mysql服务 sudo apt-get remove mysql-server 删除其他组件 sudo apt-get aut ...

  4. java 调用阿里云短信接口,报InvalidTimeStamp.Expired : Specified time stamp or date value is expired.

    官网解释: 问题所在: 自己的电脑(或者服务器) 的时间与阿里云的服务器时间 相差15分钟了. 解决方法 : 把自己的电脑时间 (或者服务器)的时间 改成标准的北京时间就行了.

  5. UniGUI之Login窗口(10)

    在UniGUI的CHM帮助里读到的. 一定要新建一个其他空白的工程,然后再添加LoginForm LoginForm 是另一种特殊的表单类型, 仅用于登录目的. 此操作将创建一个与常规窗体外观相同的空 ...

  6. K8S LoadBalance 私有环境解决方案 == metallb 工具安装和使用介绍

    接着上文,排除故障后,我重新配置了metallb组件到k8s环境. metallb为k8s service 的loadbalance负载方式提供免费的解决方案. external-ip的收费方案,可以 ...

  7. 使用JNA替代JNI调用本地方法

    JNA全称是Java Native Access,是Sun推出的一种调用本地方法技术,比起它的同门师兄JNI,JNA大大简化了调用本地方法的过程,使用也比较方便, JNA是在JNI的基础上完善的,用青 ...

  8. 配置<welcome-file>为自定义路径

    welcome-file是web.xml中的一个配置,其作用是配置启动项目时默认跳转的欢迎页面,一般我们会将其指定为一个静态页面. 那如果我们要将自定义的请求路径作为欢迎页面该怎么做呢? 1.配置we ...

  9. python中metaclass的工作原理

    class TMetaclass(type): def __new__(cls, name, bases, attrs): print(cls, name, bases, attrs) return ...

  10. 标准模板库中的链表(list)

    //C++数据结构与算法(第4版) Adam Drozdek 著  徐丹  吴伟敏<<清华大学出版社>> 头文件:include<list> list() 创建一个 ...