[STL] day 1~2 Problem Set
Q#1
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void print(int& t){ //for_each fnc: parameter accept elements T
cout << t << " ";
}
int main() {
vector<int> v;
int num, toPut;
cin >> num;
; i<num; i++) {
cin >> toPut;
v.push_back(toPut);
}
sort(v.begin(), v.end());
for_each(v.begin(), v.end(), print); //calling fnc in for_each
;
}
Q#2
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void print(int& i){
cout << i << " ";
}
int main() {
vector<int> v;
int size, num;
cin >> size;
; i<size; i++){
cin >> num;
v.push_back(num);
}
int toErase1, toErase2;
cin >> toErase1;
v.erase(v.begin()+toErase1-);
cin >> toErase1 >>toErase2;
toErase1--; toErase2--;
v.erase(v.begin()+toErase1, v.begin()+toErase2); //last one exclusive
cout << v.size() <<endl;
for_each(v.begin(), v.end(), print);
;
}
Q#3: time-out exception
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
vector<int> v;
int size, num, time, target;
cin >> size;
; i<size; i++){
cin >> num;
v.push_back(num);
}
cin >> time;
; t<time; t++){ //start testing each case
cin >> target;
;
for(; i<v.size(); i++){
if(v[i]!=target) continue;
<<endl; break;
}
if(i == v.size()){
; j<v.size(); j++){
<<endl; break;} //should not forget the {} in one-line code
}
}
}
}
Q#4
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <set>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main() {
set<int> s;
int num, enquiryType, item;
cin >> num;
while(num){
cin>>enquiryType;
cin >> item;
switch(enquiryType){
: s.insert(item); break;
: s.erase(item); break;
: {
set<int>::const_iterator p = s.find(item);
if(p!=s.end()) cout << "Yes" <<endl; //cannot use if(p!=NULL); Cz even p == v.end(), v.end()!=NULL;
else cout << "No" <<endl;
break;
}
}
num--;
}
}
Q#5
#include <cstdio>
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main() {
map<string, int> students;
int num, marks, choice;
string name;
cin >> num;
while(num){
cin >> choice >> name;
switch(choice){
: {
cin >> marks;
map<string, int>::iterator p = students.find(name); //stl algorithm needed be called by a STL CONTAINER! NOT STANDALONE!
if(p!=students.end()){ //rmb: after 'find()' algorithm, found if p!=container.end();
&& marks!= && marks!=) students[name] += marks; //container name with key represents the value it contains!
break;
}
&& marks!= && marks!=) students.insert(pair<string, int>(name, marks));
));
break;
}
: {
students.erase(name); break;
}
:{
cout << students[name] <<endl;
}
}
num--;
}
}
[STL] day 1~2 Problem Set的更多相关文章
- STL UVA 11991 Easy Problem from Rujia Liu?
题目传送门 题意:训练指南P187 分析:用vector存id下标,可以用map,也可以离散化用数组存(发现不用离散化也可以) map #include <bits/stdc++.h> u ...
- STL之父Stepanov谈泛型编程的发展史
这是一篇Dr. Dobb's Journal对STL之父stepanov的采访.文中数次提到STL的基本思想.语言的特性.编程的一些根本问题等,非常精彩.这篇文章让我想去拜读下stepanov的大作& ...
- codevs http://www.codevs.cn/problem/?problemset_id=1 循环、递归、stl复习题
12.10高一练习题 1.要求: 这周回顾复习的内容是循环.递归.stl. 不要因为题目简单就放弃不做,现在就是练习基础. 2.练习题: (1)循环 题目解析与代码见随笔分类 NOI题库 htt ...
- UVa 11991:Easy Problem from Rujia Liu?(STL练习,map+vector)
Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for example, ...
- [UVA] 11991 - Easy Problem from Rujia Liu? [STL应用]
11991 - Easy Problem from Rujia Liu? Time limit: 1.000 seconds Problem E Easy Problem from Rujia Liu ...
- Problem I: STL——多重集的插入和删除
Problem I: STL--多重集的插入和删除 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1729 Solved: 1258[Submit][ ...
- HDU - 1022 Train Problem I STL 压栈
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1022 Train Problem I(栈的应用+STL)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- uva 11991 - Easy Problem from Rujia Liu?(STL)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=3142" target="_blank ...
随机推荐
- linux 下载文件到本地磁盘的命令是什么
linux下可以直接运行命令下载或上传文件1.检查并安装相应的包:yum install lrzsz2.使用 sz 文件名 现在相应的文件到本地磁盘.3.上传使用rz 选择相应文件即可.
- 如何解释json的字符串
public void getToken(){ String json = getJedis().get("f2b9152f36424e8b8a454df9b50eb743"); ...
- Python3.5学习笔记-列表、元组、字典
Python中的变量不需要声明.每个变量在使用前都必须赋值,变量赋值以后该变量才会被创建.在Python中,变量就是变量,它没有类型,我们所说的"类型"是变量所指的内存中对象的类型 ...
- css3学习系列之移动(一)
transform功能 放缩 使用sacle方法实现文字或图像的放缩处理,在参数中指定缩放倍率,比如sacle(0.5)表示缩小50%,例子如下: <!DOCTYPE html> < ...
- CSS样式之连接方式
前言:上一篇博客是HTML基本结构和标签,是笔者学习HTML的笔记,本篇博客开始记录CSS,废话不多说,直接进入主题. 首先,我们要知道CSS是什么.简单地说,CSS层叠样式表是用来表现HTML或XM ...
- c# 测试通过
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data; using S ...
- React Image加载图片过大导致ListView滑动卡顿
今天莫名的发现ListView加载Item很卡,一顿一顿的... ListView Item 中只加载一张图片,小编从百度爸爸上随便复制的链接,这张图片很大,以致埋下如此大坑... Image的Sty ...
- 从零搭建DotnetCore2.0
右键解决方案>新建项目> 选择Web>ASP.NETCoreWeb应用程序(.NET Core) 选择Web应用程序,暂时不选择启用Docker,身份验证选择个人用户账户(会自动生成 ...
- JQuery学习笔记——基础选择器
第一篇博客,现在原生安卓需求不大了.招聘的Android工程师都需要附带更多的其他技术.这也是开启我学习前端之路的开端.前端时间看了HTML.CSS等,在界面渲染这一块,就不多记录博客了.现在学习着J ...
- css3变换,过度,动画实现梦幻网页
html和css3一出,整个互联网设计发生了颠覆性的改变,各大IT企业也推出了很多新颖的设计,比如百度浏览器的下载首页,fullpage设计风格加css动画让网页看起来很流畅舒服. css3的变换有3 ...