STL练习板子题(c++11警告)
第一题 词典
总时间限制: 3000ms 内存限制: 65536kB
描述
你旅游到了一个国外的城市。那里的人们说的外国语言你不能理解。不过幸运的是,你有一本词典可以帮助你。
输入
首先输入一个词典,词典中包含不超过100000个词条,每个词条占据一行。每一个词条包括一个英文单词和一个外语单词,两个单词之间用一个空格隔开。而且在词典中不会有某个外语单词出现超过两次。词典之后是一个空行,然后给出一个由外语单词组成的文档,文档不超过100000行,而且每行只包括一个外语单词。输入中出现单词只包括小写字母,而且长度不会超过10。
输出
在输出中,你需要把输入文档翻译成英文,每行输出一个英文单词。如果某个外语单词不在词典中,就把这个单词翻译成“eh”。
样例输入
dog ogday
cat atcay
pig igpay
froot ootfray
loops oopslay
atcay
ittenkay
oopslay
样例输出
cat
eh
loops
#include<iostream>
#include<cstdio>
#include<fstream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
#include<string>
#include<list>
using namespace std;
int read(){
char ch;
int res=,f=;
ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<=''){
res=res*+(ch-'');
ch=getchar();
}
return res*f;
}
map<string,string>u;
string s,k,g;
int y;
int main(){
while(){
getline(cin,s);
y=s.find(' ');
if(y!=s.npos){
k=s.substr(,y+);
g=s.substr(y+);
u.insert(make_pair(g,k));
}
else break;
}
while(cin>>s){
if(u.count(s))cout<<u[s]<<endl;
else cout<<"eh"<<endl;
}
return ;
}
第二题 list
总时间限制: 4000ms 内存限制: 65536kB
描述
写一个程序完成以下命令:
new id ——新建一个指定编号为id的序列(id<10000)
add id num——向编号为id的序列加入整数num
merge id1 id2——合并序列id1和id2中的数,并将id2清空
unique id——去掉序列id中重复的元素
out id ——从小到大输出编号为id的序列中的元素,以空格隔开
输入
第一行一个数n,表示有多少个命令( n<=200000)。以后n行每行一个命令。
输出
按题目要求输出。
样例输入
16
new 1
new 2
add 1 1
add 1 2
add 1 3
add 2 1
add 2 2
add 2 3
add 2 4
out 1
out 2
merge 1 2
out 1
out 2
unique 1
out 1
样例输出
1 2 3
1 2 3 4
1 1 2 2 3 3 4
1 2 3 4
#include<iostream>
#include<cstdio>
#include<fstream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
#include<string>
#include<list>
using namespace std;
int read(){
char ch;
int res=,f=;
ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<=''){
res=res*+(ch-'');
ch=getchar();
}
return res*f;
}
list<int>u[];
string order;
int n,a,b;
int main(){
n=read();
for(int i=;i<=n;++i){
cin>>order;
if(order=="new"){
a=read();
}
else if(order=="add"){
a=read();b=read();
u[a].push_back(b);
}
else if(order=="merge"){
a=read();b=read();
u[a].splice(end(u[a]),u[b]);
}
else if(order=="unique"){
a=read();
u[a].sort();
u[a].unique();
}
else{
a=read();
u[a].sort();
for(auto iter=begin(u[a]);iter!=end(u[a]);++iter){
printf("%d ",*iter);
}
printf("\n");
}
}
return ;
}
第三题 set
现有一整数集(允许有重复元素),初始为空。我们定义如下操作:
add x 把x加入集合
del x 把集合中所有与x相等的元素删除
ask x 对集合中元素x的情况询问
对每种操作,我们要求进行如下输出。
add 输出操作后集合中x的个数
del 输出操作前集合中x的个数
ask 先输出0或1表示x是否曾被加入集合(0表示不曾加入),再输出当前集合中x的个数,中间用空格格开。
输入
第一行是一个整数n,表示命令数。0<=n<=100000。
后面n行命令,如Description中所述。
输出
共n行,每行按要求输出。
样例输入
7
add 1
add 1
ask 1
ask 2
del 2
del 1
ask 1
样例输出
1
2
1 2
0 0
0
2
1 0
#include<iostream>
#include<cstdio>
#include<fstream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
#include<string>
#include<list>
#include<set>
using namespace std;
int read(){
char ch;
int res=,f=;
ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<=''){
res=res*+(ch-'');
ch=getchar();
}
return res*f;
}
int n,a;
multiset<int>u;
string order;
bool t[];
int main(){
n=read();
for(int i=;i<=n;++i){
cin>>order;
if(order=="add"){
a=read();
t[a]=;
u.insert(a);
printf("%d\n",u.count(a));
}
else if(order=="del"){
a=read();
printf("%d\n",u.count(a));
u.erase(a);
}
else{
a=read();
printf("%d %d\n",t[a],u.count(a));
}
}
return ;
}
STL练习板子题(c++11警告)的更多相关文章
- 堆以及一些用法 QWQ这是写得最认真的板子题
最近一直在学图论,然后吧,由于学的东西实在是太多太杂了,加上蒟蒻本蒻又经常颓,所以落了好多好多板子题的整理没写啊嘤嘤嘤,不过把这些东西学的差不多了,再一块写个整理,其实感觉还不错?????也算是很神奇 ...
- 病毒侵袭 HDU - 2896 板子题
当太阳的光辉逐渐被月亮遮蔽,世界失去了光明,大地迎来最黑暗的时刻....在这样的时刻,人们却异常兴奋--我们能在有生之年看到500年一遇的世界奇观,那是多么幸福的事儿啊~~ 但网路上总有那么些网站,开 ...
- POJ 1321 棋盘问题(DFS板子题,简单搜索练习)
棋盘问题 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44012 Accepted: 21375 Descriptio ...
- POJ 3278 Catch That Cow(BFS,板子题)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 88732 Accepted: 27795 ...
- Gym 100952J&&2015 HIAST Collegiate Programming Contest J. Polygons Intersection【计算几何求解两个凸多边形的相交面积板子题】
J. Polygons Intersection time limit per test:2 seconds memory limit per test:64 megabytes input:stan ...
- hihoCoder #1038 : 01背包(板子题)
#1038 : 01背包 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 且说上一周的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到了小Ho领取奖励 ...
- [LOJ 6270]数据结构板子题
Description 有n个区间,第i个区间是[li,ri],它的长度是ri−li. 有q个询问,每个询问给定L,R,K,询问被[L,R]包含的且长度不小于K的区间数量. 你想,像这种板子题,你随手 ...
- bzoj-1787-洛谷-4281(LCA板子题)
传送门(bzoj) 传送门(洛谷) 可以说这道也是一个板子题 由于题中是三个人需经过的路径最短 就会有一点点不太一样 那么 就两两求LCA 这样之后就会出现两种状况 一.所得到的三个LCA是相等的 那 ...
- bzoj3944: Sum 杜教筛板子题
板子题(卡常) 也可能是用map太慢了 /************************************************************** Problem: 3944 Us ...
随机推荐
- Python--时间模块time模块
原地址:https://finthon.com/python-time/ Python时间模块——time模块 简介 在数据处理当中,经常会碰到处理时间的问题.比如:在序列预测的过程中,需要通过学习一 ...
- chrome中显示DNS_PROBE_FINISHED_NO_INTERNET无法上网,但是IE可以上
以管理员方式运行cmd,执行如下命令 ipconfig /release ipconfig /all ipconfig /flushdns ipconfig /renew netsh int ip s ...
- tomcat中server.xml各项配置详解
详见大佬的文章,乐于做大佬文章的搬运工. http://www.cnblogs.com/starhu/p/5599773.html
- asp.net core-9.依赖注入的使用
http://www.jessetalk.cn/2017/11/06/di-in-aspnetcore/
- JS强制关闭浏览器页签并且不提示关闭信息
工作中很多奇葩的需求都会出现,现在就有一个问题,描述如下: 现在的登录跳转权限页面要去掉,集成在第三方系统信息上,当退出登录的时候需要关掉打开的Tab页面,因此考虑使用window.close()关闭 ...
- hdu 6216 A Cubic number and A Cubic Number
题意:给定一个素数,判定它是不是两个立方数之差. 题解:对于a^3+b^3=(a-b)(a^2-a*b+b^2),而一个素数的因子只有1和其本身,在加上(a^2-a*b+b^2)一定是大于1的,所以只 ...
- 数据库及MySQL基础(1)
1.数据库概述 关系型数据库:面对关系,Java面向对象. ·常见数据库 Oracle(神喻):甲骨文 DB2:IBM SQL Server:微软 Sybase:赛尔斯 MySQL:甲骨文,最早是开源 ...
- Windows 下 mysql 5.7 设置 区分大小写(敏感),设置默认编码 utf8mb4
修改编码 c盘下搜索 C:\ProgramData\MySQL\MySQL Server 5.7 在该my.ini文件下进行配置修改 [client] default-character-set = ...
- VBA if语句
一个if语句由一个布尔表达式和一个或多个语句组成.如果条件被评估为True,则执行If条件块下的语句.如果条件被评估为False,则执行If循环块后面的语句. 语法 以下是VBScript中的If语句 ...
- impdp时报错ORA-39083&ORA-01917
转自:http://www.codes51.com/article/detail_146662.html impdp时报错ORA-39083&ORA-01917ORA-39083: 对象类型 ...