每日一九度之 题目1041:Simple Sorting
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:4883
解决:1860
- 题目描述:
-
You are given an unsorted array of integer numbers. Your task is to sort this array and kill possible duplicated elements occurring in it.
- 输入:
-
For each case, the first line of the input contains an integer number N representing the quantity of numbers in this array(1≤N≤1000). Next N lines contain N integer numbers(one number per each line) of the original array.
- 输出:
-
For each case ,outtput file should contain at most N numbers sorted in ascending order. Every number in the output file should occur only once.
- 样例输入:
-
6
8 8 7 3 7 7
- 样例输出:
-
3 7 8
本来想用桶排做的,提交后发现runtime error,应该是数的范围太宽了。
//Asimple
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <limits.h>
#define INF 0x7fffffff
using namespace std;
const int maxn = ;
typedef long long ll;
int n, num;
int a[maxn]; int main(){
while( ~scanf("%d",&n) ){
memset(a,,sizeof(a));
while( n -- ){
scanf("%d",&num);
a[num] = ;
}
int k = ;
for(int i=; i<maxn; i++){
if( a[i] ){
printf(k==?"%d":" %d",i);
k ++;
}
}
printf("\n");
}
return ;
}
正解,用STL中的set正好。简单,明了!!
//Asimple
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <limits.h>
#define INF 0x7fffffff
using namespace std;
const int maxn = ;
typedef long long ll;
int n, num;
set<int> s; int main(){
while( ~scanf("%d",&n) ){
s.clear();
while( n -- ){
scanf("%d",&num);
s.insert(num);
}
set<int>::iterator it;
for(it=s.begin(); it!=s.end(); it++){
printf(it==s.begin()?"%d":" %d",*it);
}
printf("\n");
}
return ;
}
每日一九度之 题目1041:Simple Sorting的更多相关文章
- 九度oj 题目1041:Simple Sorting
题目描述: You are given an unsorted array of integer numbers. Your task is to sort this array and kill p ...
- 每日一九度之 题目1076:N的阶乘
时间限制:3 秒 内存限制:128 兆 特殊判题:否 提交:7601 解决:2749 题目描述: 输入一个正整数N,输出N的阶乘. 输入: 正整数N(0<=N<=1000) 输出: 输入可 ...
- 每日一九度之 题目1043:Day of Week
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:7336 解决:2563 题目描述: We now use the Gregorian style of dating in Russia. ...
- 每日一九度之 题目1042:Coincidence
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3007 解决:1638 题目描述: Find a longest common subsequence of two strings. 输入 ...
- 每日一九度之 题目1040:Prime Number
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6732 解决:2738 题目描述: Output the k-th prime number. 输入: k≤10000 输出: The k- ...
- 每日一九度之 题目1038:Sum of Factorials
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2109 解决:901 题目描述: John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, ...
- 每日一九度之 题目1039:Zero-complexity Transposition
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3372 解决:1392 题目描述: You are given a sequence of integer numbers. Zero-co ...
- 每日一九度之 题目1033:继续xxx定律
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5502 解决:1351 题目描述: 当n为3时,我们在验证xxx定律的过程中会得到一个序列,3,5,8,4,2,1,将3称为关键数, ...
- 每日一九度之 题目1031:xxx定律
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6870 解决:4302 题目描述: 对于一个数n,如果是偶数,就把n砍掉一半:如果是奇数,把n变成 3*n+ 1后砍掉一半,直到该数 ...
随机推荐
- RDIFramework.NET — 基于.NET的快速信息化系统开发框架 - 5.3 数据库连接管理模块
RDIFramework.NET — 基于.NET的快速信息化系统开发框架 5.3 数据库连接管理模块 5.3 数据库连接管理模块 我们经常可以看到很多软件直接把数据库连接字符串放在软件执行目录下的配 ...
- MVC ViewModel
ViewModel这个概念不只是在在MVC模式中有,你会在很多关于MVC.MVP.MVVM的文章中见到这个说法,并且这个概念在任何技术中都有可能提到,比如ASP.NET, Silverlight, W ...
- sql语句查询出数据重复,取唯一数据
select distinct mr.id,ifnull(mr.pid,0) as pid,mr.name from sys_role_res srr left join main_res mr on ...
- NSString
// —————————NSString // NSString //1.初始化:直接字符串.格式化字符串.文件读取内容初始化 NSString *str1 = @"hello world! ...
- hibernate主键生成机制与save返回
主键生成机制为assigned时,save之后通过get得不到id(主键),使用identity可以. hibernate主键生成机制1) assigned主键由外部程序负责生成,无需Hibernat ...
- C++Primer 第十三章
//1.当定义一个类时,我们显示地或隐式地指出在此类型的对象(注意这里是此类型的对象,而不包括此类型的指针)拷贝,移动,赋值,销毁时做什么.一个类通过定义五种特殊的成员函数来控制这些操作:拷贝构造函数 ...
- 一个新人对JavaScript的内容简单介绍
JavaScript 1.基本的数据类型:字符串 小数 整数 时间日期 布尔型等. 2.变量: JS定义变量通通都是用var开头,var里面可以放任何东西(如:小数,整数,字符串,时间日期等等 ...
- Ubuntu 16.04 LTS Final Beta
期待已久的Ubuntu LTS 版本开放了公测版本 Ubuntu 16.04 (Xenial Xerus) Daily Build(http://cdimage.ubuntu.com/daily-l ...
- R12 供应商SQL
-- 供应商主表数据: SELECT ass.vendor_id vendor_id, ass.party_id party_id, ass.segment1 vendor_code, ass.ven ...
- 夺命雷公狗ThinkPHP项目之----企业网站18之网站配置列表页的完成
我们点击下配置列表即可查看我们列表页的配置信息了: 其实这个最简单了,首先我们先来完成他控制器的代码: public function lists(){ $mod = M('Conf')->se ...