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. 如何解决苹果Mac系统无法识别U盘

       1.在Mac机上打开“磁盘工具”,将U盘重新分区, 2.格式选“exFAT”.该格式分区Win及Mac系统中都可以读和写,特别是可以支持大于4GB的大文件.但是一些高清播放机可能不支持. 3.以 ...

  2. 【LeetCode】144. Binary Tree Preorder Traversal

    题目: Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binar ...

  3. 分享几个 git 的使用场景

    你真的会使用 git 吗?你能回答下面几个问题吗? 有三个commit(顺序:CommitA.CommitB.CommitC),它们相互独立,没有依赖. 在不修改B.C的前提下,修改A,怎么操作? 合 ...

  4. 8.javaweb之session

    session是客户端和服务端的一次会话 web的session是指用户在浏览某个网站时,从进入网站到关闭浏览器的这段时间,uyejiushi用户浏览这个网站所花费的时间. session是一个时间的 ...

  5. voa 2015.4.29

    Nepal has declared three days of mourning for the victims of Saturday's 7.8 magnitude earthquake tha ...

  6. OpenStack neutron 环境云主机使用keepalived vip + 给vip绑定浮动IP 步骤及注意事项

    在openstack环境创建的多台云主机配置keepalived作主备,默认情况下无法生效,直接对云主机一张网卡配置两个IP进行测试也是同样结果,因为: 可以看到,port所在的宿主机上iptable ...

  7. sqlserver提高篇续集

    七.数据完整性 1.概念:数据一致性和准确性. 分类:域完整性.实体完整性.引用完整性. 解析:域完整性也叫列完整性是指一个数据集对某个列是否有效和确定是否允许为空值.实体完整性也叫行完整性 要求所有 ...

  8. MyBatis+mysql 简单分页

    注意:limit不能跟动态内容 <select id="fenYe" parameterType="int" resultType="com.x ...

  9. C# 代码规范和质量检查工具 StyleCop.Analyzers

    简介 原来一直用 ReSharper 来进行代码质量检查,不过毕竟是收费的,所以想找个免费的可以推广给公司的同事也一起用.搜索了一下,找到了StyleCop,但是我在 VS 2015里安装 Style ...

  10. 【Django】django 处理request流程细节(转)

    首先发生的是一些和 Django 有关(前期准备)的其他事情,分别是: 如果是 Apache/mod_python 提供服务,request 由 mod_python 创建的 django.core. ...