STL练习题续
//zjnu 1399
//sort 数组可用
//vector sort(vector)
#include<iostream>
#include<algorithm>
using namespace std;
int s[];
int main()
{
int n;
int i;
int k=;
while(scanf("%d",&n)&&n!=-)
{
k++;
for(i=;i<n;i++)
scanf("%d",&s[i]);
sort(s,s+n);
printf("Case number:%d\n",k);
printf("Number of elements:%d\n",n);
for(i=;i<n-;i++)
printf("%d ",s[i]);
printf("%d\n",s[n-]);
}
} #include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
int main()
{
vector<int>a;
int n,x,k=;
while(scanf("%d",&n)&&n!=-)
{
a.clear();
for(int i=;i<n;i++)
{
scanf("%d",&x);
a.push_back(x);
}
sort(a.begin(),a.end());//vector的sort用法
printf("Case number:%d\n",++k);
printf("Number of elements:%d\n",n);
for(int i=;i<a.size()-;i++)
printf("%d ",a[i]);
printf("%d\n",a[a.size()-]);
}
system("pause"); }
//zjnu 1042 map
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<map>
#include<cstring>
using namespace std;
map<int,int>cl;
map<int,int>::iterator it;
int a[];
int main()
{
int n;
while(~scanf("%d",&n))
{
int i,x;
cl.clear();
for(i=;i<=n;i++)
{
scanf("%d",&x);
cl[x]++;
}
for(it=cl.begin();it!=cl.end();it++)
{
printf("%d %d\n",(*it).first,(*it).second);
}//first 指向x的值 second指向 cl[]的值
}
return ;
}
//zjnu 1407
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
struct node{
int x,y,z;
}s[];
bool cmp(node a,node b)
{
if(a.x==b.x&&a.y==b.y)
return a.z<b.z;
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
int main()
{
int t,n,i;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%d%d%d",&s[i].x,&s[i].y,&s[i].z);
}
sort(s,s+n,cmp);
printf("%d\n",n);
for(i=;i<n;i++)
printf("%d %d %d\n",s[i].x,s[i].y,s[i].z);
}
}
//zjnu 1403 全排列
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int a[];
int main()
{
int n,m,i,j;
while(~scanf("%d%d",&n,&m))
{
for(i=;i<n;i++)
a[i]=i+;
for(j=;j<m;j++)
next_permutation(a,a+n);
for(i=;i<n-;i++)
printf("%d ",a[i]);
printf("%d\n",a[n-]);
}
return ;
}
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
struct node{
int num,rank;
friend bool operator<(node a,node b)
{
if(a.rank==b.rank)
return a.num>b.num;//在后面的优先级高
return a.rank<b.rank;
}
};
int main()
{
int t,i,n,m;
char s[];
node x;
while(~scanf("%d",&t))
{
priority_queue<node>q[];//每次都要重新定义队列
int id=;
while(t--)
{
scanf("%s",s);
if(s[]=='I')
{
scanf("%d%d",&n,&m);
x.rank=m;
x.num=id++;
q[n].push(x);
}
else
{
scanf("%d",&n);
if(q[n].empty())
printf("EMPTY\n");
else
{
printf("%d\n",q[n].top().num);
q[n].pop();
}
}
}
}
return ;
}
STL练习题续的更多相关文章
- C#与C++相比较之STL篇(续一)
本篇接<C#与C++相比较之STL篇>,主要探索C++STL的两个组件:算法和仿函数,以及C#的linq和拉姆达表达式.委托. STL的算法与仿函数 算法是个庞大的主题,STL包含了超过1 ...
- STL练习题
//hdu_2717 //map 一对多映射,基于关键字快速查找,不允许重复值 //queue 队列 先进先出 #include<iostream> #include<cstdio& ...
- Team Queue(STL练习题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1387 Team Queue Time Limit: 2000/1000 MS (Java/Others ...
- 【tyvj】刷题记录(1001~1099)(64/99)
1001:排序完按照题意做即可. #include<cstdio> #include<iostream> #include<cmath> #include<a ...
- 洛谷 P1360 [USACO07MAR]Gold Balanced Lineup G (前缀和+思维)
P1360 [USACO07MAR]Gold Balanced Lineup G (前缀和+思维) 前言 题目链接 本题作为一道Stl练习题来说,还是非常不错的,解决的思维比较巧妙 算是一道不错的题 ...
- C++STL标准库学习笔记(四)multiset续
自定义排序规则的multiset用法 前言: 在这个笔记中,我把大多数代码都加了注释,我的一些想法和注解用蓝色字体标记了出来,重点和需要关注的地方用红色字体标记了出来,只不过这一次的笔记主要是我的补充 ...
- codevs http://www.codevs.cn/problem/?problemset_id=1 循环、递归、stl复习题
12.10高一练习题 1.要求: 这周回顾复习的内容是循环.递归.stl. 不要因为题目简单就放弃不做,现在就是练习基础. 2.练习题: (1)循环 题目解析与代码见随笔分类 NOI题库 htt ...
- STL源码剖析读书笔记--第四章--序列式容器
1.什么是序列式容器?什么是关联式容器? 书上给出的解释是,序列式容器中的元素是可序的(可理解为可以按序索引,不管这个索引是像数组一样的随机索引,还是像链表一样的顺序索引),但是元素值在索引顺序的方向 ...
- (转载)C++:STL标准入门汇总
(转载)http://www.cnblogs.com/shiyangxt/archive/2008/09/11/1289493.html 学无止境!!! 第一部分:(参考百度百科) 一.STL简介 S ...
随机推荐
- 使用Cookie实现跨域单点登录的原理
对于构建分布式系统来说业务功能的物理部署会随着新业务模块的增加而增加或改变物理部署的位置.而每个用户都有统一的帐号作为我们登录系统时的一个认证.当新业务或子系统部署在不同的物理机上,我们去访问不同的业 ...
- instruments usage error specified target process is invalid
遇到这个问题的很多,但都没说具体的解决办法. 如果你的包名 路径之类的都正确,还是报这个错误的话,请重启手机.
- 《Reactive_MircService_Architecture》 脑图
Reactive_MircService_Architecture Lightbend CTO的50页的小册子,对响应式系统以及微服务架构介绍非常全面,整理了一个脑图来先.
- 拼图 canvas分割 dom拖拽 pc 移动端
参考:Canvas drag 实现拖拽拼图小游戏 参考的案例,不支持手机端.总结下实现过程中遇到的小坑. gitHub:https://github.com/WppFrontEnd/puzzle 大概 ...
- js ShowDialogModal 关闭子页面并刷新父页面,保留查询条件
不知道大家有没有碰到类似的问题,当时的你是什么思路来处理这个问题呢?是url,session,cookie,还是…… 今天笔者就遇到了这个问题,当时的想法如:url,session,cookie都尝试 ...
- SQL Server 查询所有外键子父表关系
SELECT table_name,fk_name,reference_table_name,fk_list_number,fk_detailFROM (SELECT object_name(f.ob ...
- 使用afinal下载文件并且在状态栏中显示下载的进度
2013年10月23日,今天是在“我在找你信息服务有限公司”第一天上班,公司给提出了这样一个要求:下载本公司的app,并且在下载的过程中要在状态栏中显示下载的进度,并且,可以暂停和继续下载. 下面是我 ...
- tkinter 在 x window 下的字体设置格式
X Font Descriptors # X Font Descriptors are strings having the following format (the asterisks repre ...
- R语言读取excel文件的3种方法
R读取excel文件中数据的方法: 电脑有一个excel文件,原始的文件路径是:E:\R workshop\mydata\biom excel数据为5乘2阶矩阵,元素为 ...
- UML类图6种关系的总结
http://www.open-open.com/lib/view/open1328059700311.html