[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 ...
随机推荐
- Entity Framework入门教程:创建实体数据模型
下图为一个已经创建好的数据库表关系 实体数据模型的创建过程 在Visual Studio项目中,右键程序集菜单,选择[添加]->[新建项],在[添加新项窗口]中选择[ADO.NET实体数据模型] ...
- CSS样式之选择器
一.CSS选择器构成 CSS选择器是你想要改变样式的html元素,通俗的说,选择器可以改变html文件中标签的属性,这些属性可以是颜色,背景图,字体等.每个选择器有一条或多条声明,可以同时改变某个标签 ...
- webpack1 新手入门教程
本文github仓库地址: https://github.com/Rynxiao/webpack-tutorial ,里面包括了本教程的所有代码. [如果你觉得这篇文章写得不错,麻烦给本仓库一颗星:- ...
- 在Linux环境如何在不解压情况下搜索多个zip包中匹配的字符串内容
今天有个生产文件需要查日志,但因为是比较久远的故障,日志已经被归档为zip包放到某个目录下了,在不知道具体日期时间的情况下,总不能一个一个解压搜索吧.于是就研究一下怎么在多个压缩包里搜索字符串了.目前 ...
- voa 2015 / 4 / 27
As reports of the death toll rise in Nepal, countries and relief organizations around the world are ...
- Maven学习专题--Maven入门及安装
因为项目需要,新项目需要使用Maven开发,但是组内大部分没有接触过maven.我就毅然承担搭建maven环境的任务了.因为一切重头开始,就想把自己的整个搭建环境.项目创建.框架整合和模块管理整个过程 ...
- Servlet 中为多项选择题判分---String类的indexOf()方法妙用
首先来看一下String类的indexOf()方法的用法: public class FirstDemo1 { /** *API中String的常用方法 */ // 查找指定字符串是否存在 publi ...
- 4,JPA-Hibernate
一,什么是JPA JPA全称Java Persistence API.JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中. JPA(Java Pers ...
- Entity Framework Core 软删除与查询过滤器
本文翻译自<Entity Framework Core: Soft Delete using Query Filters>,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 注意 ...
- 学习笔记TF026:多层感知机
隐含层,指除输入.输出层外,的中间层.输入.输出层对外可见.隐含层对外不可见.理论上,只要隐含层节点足够多,只有一个隐含层,神经网络可以拟合任意函数.隐含层越多,越容易拟合复杂函数.拟合复杂函数,所需 ...