[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 ...
随机推荐
- Gist - ES6 Iterator
Introduction Iterator is one of the most common design modes in daily development. Let's explore the ...
- java数组降序排序之冒泡排序
import java.util.Arrays;//必须加载 class Demo{ public static void main(String []args){ int[] arr={3,54,4 ...
- 【Android Developers Training】 5. 序言:添加Action Bar
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- iOS 实时录音和播放
需求:最近公司需要做一个楼宇对讲的功能:门口机(连接WIFI)拨号对室内机(对应的WIFI)的设备进行呼叫,室内机收到呼叫之后将对收到的数据进行UDP广播的转发,手机(连接对应的WIFI)收到视频流之 ...
- net 中web.config单一解决方法 (其他配置引入方式)
近期一个项目需要写许多的配置项,发现在单个web.config里面写的话会很乱也难于查找 所以搜了一下解决了,记录下来 一. webconfig提供了引入其他config的方式 <conne ...
- MyBatis源码解析【3】生命周期
经过之前的项目构建,我们已经得到了一个可以使用的最基本的项目. 其中已经包括整个执行的过程.但是我们在完成之后也遇到了很多问题,我们就要慢慢的一步步解决这些问题. 讲道理,今天我们其实应该直接开始看源 ...
- oracle批量数据导入工具 sqlldr
sqlldr工具参数: [oracle@server ~]$ sqlldr SQL*Loader: Release - Production on Wed Nov :: Copyright (c) , ...
- vijos1090题解
题目: 有n个正整数排成一行.你的目的是要从中取出一个或连续的若干个数,使它们的和能够被k整除. 例如,有6个正整数,它们依次为1.2.6.3.7.4.若k=3,则你可以取出1.2.6,或者2.6.3 ...
- Akka(12): 分布式运算:Cluster-Singleton-让运算在集群节点中自动转移
在很多应用场景中都会出现在系统中需要某类Actor的唯一实例(only instance).这个实例在集群环境中可能在任何一个节点上,但保证它是唯一的.Akka的Cluster-Singleton提供 ...
- @RequestParam与@PathVariable的区别
在spring MVC中,两者的作用都是将request里的参数的值绑定到contorl里的方法参数里的,区别在于,URL写法不同. 使用@RequestParam时,URL是这样的:http://h ...