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. 浏览器控制台报Cannot read property 'conf' of undefined

    原因:JS中有个变量没有类型导致 解决:加上类型即可(我是少写了var)

  2. Codeforces1303D. Fill The Bag

    1e18对应2进制有58位,可以直接暴力模拟,因为读入的数都是2次幂,__builtin_ctz这个内置gcc函数可以算出二进制下末尾有几个0,读入时统计,然后从n的最低位开始判断,注意每次升位的时候 ...

  3. Java程序基本优化

    1.尽量指定类的final修饰符,因为带有final修饰符的类是不可派生的. 2.尽量重用对象. 3.尽量使用局部变量. 4.不要重复初始化变量. 5.在Java+Oracle的应用系统开发中,Jav ...

  4. Java单例模式:为什么我强烈推荐你用枚举来实现单例模式

    单例模式简介 单例模式是 Java 中最简单,也是最基础,最常用的设计模式之一.在运行期间,保证某个类只创建一个实例,保证一个类仅有一个实例,并提供一个访问它的全局访问点.下面就来讲讲Java中的N种 ...

  5. pip使用镜像的方法

    http://e.pypi.python.org/这个就是官网了,清华大学提供的 建议非清华大学校内的使用这个镜像: http://e.pypi.python.org/simple(这也是一个http ...

  6. Linux CentOS7 VMware usermod命令、用户密码管理、mkpasswd命令

    一. usermod命令 usermod可用来修改用户帐号的各项设定 -c, --comment 注释 GECOS 字段的新值 -d, --home HOME_DIR 用户的新主目录 -e, --ex ...

  7. 4 (计算机网络) DHCP与PXE:IP是怎么来的,又是怎么没的?

    如何配置 IP 地址? 那如何配置呢?如果有相关的知识和积累,你可以用命令行自己配置一个地址.可以使用 ifconfig,也可以使用 ip addr.设置好了以后,用这两个命令,将网卡 up 一下,就 ...

  8. 《N诺机试指南》(一)数组妙用

    题目A: 大家思路有可能是这样: 将输入数据全部存储到一个数组里,然后可以冒泡排序一波,从小到大排序 那么怎么找到重复次数呢:我是这样想的,新定义数组b,原数组a,首先b[0] = a[0],定义指针 ...

  9. crm业务流程图(精简版)

    网址:https://www.processon.com/view/link/5e0be839e4b0aef94cbcee28#map如果链接失效,请及时反馈(在评论区评论),博主会及时更新

  10. 三级联动下拉列表——php 、Ajax

    主页面:<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF- ...