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. 2.vue 安装教程

    安装node.js 从node.js官网下载并安装node,安装过程很简单,一路"下一步"就可以了(傻瓜式安装). 安装完成之后,打开命令行工具,输入 node -v,如下图,如果 ...

  2. 4.jsp的内置对象

    1.jsp有九大内置对象 out request response session application page pagecontext exception config 2.用户发请求 requ ...

  3. webpack以及loader 加载命令

    module.exports={ entry:'./main/main.js', output:{ path:'./build', filename:'bundle.js' }, module:{ l ...

  4. [故障公告]14:40-15:00博客站点web服务器雪崩似的CPU 100%

    非常抱歉,今天下午14:40-15:00左右,web服务器突然雪崩似的出现CPU 100%问题,造成博客站点无法访问(503).由此给您带来很大的麻烦,请您谅解. 在问题出现之前,博客站点运行着5台w ...

  5. CJOJ 2022 【一本通】简单的背包问题(搜索)

    CJOJ 2022 [一本通]简单的背包问题(搜索) Description 设有一个背包可以放入的物品重量为S,现有n件物品,重量分别是w1,w2,w3,-wn. 问能否从这n件物品中选择若干件放入 ...

  6. 如何生成Azure SAS Token

    在Azure PaaS服务密钥的安全性文章中,提到过客户端实际上发送的是Token,而不是密钥.那么Token是该如何生成呢? Azure相应服务的SDK其实都提供了或者内置了生成Token的方法,可 ...

  7. Java虚拟机:GC算法深度解析

    版权声明:本文为博主原创文章,转载请注明出处,欢迎交流学习! 在前面的文章里介绍了可达性分析算法,它为我们解决了判定哪些对象可以回收的问题,接下来就该我们的垃圾收集算法出场了.不同的垃圾收集算法有各自 ...

  8. 一个简单的java贷款程序

    代码如下: //计算贷款package ClassDemo;import javax.swing.JOptionPane; public class ComputeLoan { public stat ...

  9. 如何给Ionic写一个cordova插件

    写一个cordova插件 之前由javaWeb转html5开发,由于面临新技术,遂在适应的过程中极为挣扎,不过还好~,这个过程也极为短暂:现如今面临一些较为复杂的需求还会有一丝丝头痛,却没有一开始那么 ...

  10. tensorflow elu函数应用

    1.elu函数 图像: 2.tensorflow elu应用 import tensorflow as tf input=tf.constant([0,-1,2,-3],dtype=tf.float3 ...