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的更多相关文章

  1. STL UVA 11991 Easy Problem from Rujia Liu?

    题目传送门 题意:训练指南P187 分析:用vector存id下标,可以用map,也可以离散化用数组存(发现不用离散化也可以) map #include <bits/stdc++.h> u ...

  2. STL之父Stepanov谈泛型编程的发展史

    这是一篇Dr. Dobb's Journal对STL之父stepanov的采访.文中数次提到STL的基本思想.语言的特性.编程的一些根本问题等,非常精彩.这篇文章让我想去拜读下stepanov的大作& ...

  3. codevs http://www.codevs.cn/problem/?problemset_id=1 循环、递归、stl复习题

    12.10高一练习题 1.要求: 这周回顾复习的内容是循环.递归.stl. 不要因为题目简单就放弃不做,现在就是练习基础. 2.练习题: (1)循环   题目解析与代码见随笔分类  NOI题库 htt ...

  4. 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, ...

  5. [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 ...

  6. Problem I: STL——多重集的插入和删除

    Problem I: STL--多重集的插入和删除 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1729  Solved: 1258[Submit][ ...

  7. HDU - 1022 Train Problem I STL 压栈

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. hdu 1022 Train Problem I(栈的应用+STL)

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. uva 11991 - Easy Problem from Rujia Liu?(STL)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=3142" target="_blank ...

随机推荐

  1. 调用phprpc的时候出现Fatal error: Cannot redeclare gzdecode()

    出现这个问题的原因是:php在5.4版本后,已经自包含了gzdecode()函数,开发者自己定义的gzdecode()函数会与其冲突. 在 ....\phpRPC\compat.php文件的第72行( ...

  2. Solr6.6 Tomcat8部署

    原文:https://github.com/x113773/testall/issues/6 准备工作:[solr-6.6.0](http://www.apache.org/dyn/closer.lu ...

  3. USACO hamming

    考试周终于过去了一半,可以继续写USACO了. 先来看一下题目吧. Hamming CodesRob Kolstad Given N, B, and D: Find a set of N codewo ...

  4. AJAX数据请求

    ajax数据请求需要四个步骤:(请求文本内容) 1.创建XMLHttpRequest对象: 2.打开与服务起的链接: 3.发送给服务器: 4.响应就绪. <!DOCTYPE html> & ...

  5. 使用solr6.0搭建solrCloud

    一.搭建zookeeper集群 1.下载zookeeper压缩包到自己的目录并解压(本例中的目录在/opt下),zookeeper的根目录我们在这里用${ZK_HOME}表示. 2.在${ZK_HOM ...

  6. spring +springmvc+mybatis组合总结

    springmvc+spring+mybatis整合:1. 拷贝所需jar2. 创建spring配置文件(beans.xml)3. 配置数据源 <bean id="dataSource ...

  7. mysql中exists、not exists的用法

    exists 关键字是判断是否存在的,存在则返回true,不存在则返回false, not exists则是不存在时返回true,存在返回false: 1. 最常用的if not  exists用法: ...

  8. eclipse 小方法

  9. requireJS 源码(三) data-main 的加载实现

    (一)入口 通过 data-main 去加载 JS 模块,是通过  req(cfg) 入口去进行处理的. 为了跟踪,你可以在此 加断点 进行调试跟踪. (二)  req({ })执行时,functio ...

  10. es6的模块化编程

    es6的模块化编程 基本用法 es6 中新增了两个命令 export 和 import , export 命令用于规定模块的对外接口,import 命令用于输入其他模块提供的功能. 一个模块就是一个独 ...