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. [leetcode-312-Burst Balloons]

    Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by ...

  2. 【LeetCode】136. Single Number

    题目: Given an array of integers, every element appears twice except for one. Find that single one. No ...

  3. 用php+mysql+ajax实现淘宝客服或阿里旺旺聊天功能 之 前台页面

    首先来看一下我已经实现的效果图: 消费者页面:(本篇随笔) (1)会显示店主的头像 (2)当前用户发送信息显示在右侧,接受的信息,显示在左侧 店主或客服页面:(下一篇随笔) (1)在左侧有一个列表 , ...

  4. Spring Security 概念基础 验证流程

    Spring Security 概念基础 验证流程 认证&授权 认证:确定是否为合法用户 授权:分配角色权限(分配角色,分配资源) 认证管理器(Authentication Manager) ...

  5. ASP.NET Core Web API 最小化项目

    ASP.NET Core中默认的ASP.NET Core 模板中有Web API 模板可以创建Web API项目. 有时,只需要创建一个API,不需要关心Razor,本地化或XML序列化.通过删除无用 ...

  6. Docker-compose 多个Docker容器管理:以MYSQL和Wordpress为例

    搬砖的陈大师版权所有,转载请注明:http://www.lenggirl.com/tool/docker-compose.html Docker-compose 多个Docker容器管理:以MYSQL ...

  7. 如何将md文件转换成带目录的html文件

    配置环境node 去官网下一个node安装包,下一步下一步: 由于现在的node都自带npm,直接 npm install i5ting_toc 这样安装好了i5ting_toc这个包, 进入你实现准 ...

  8. ansible的安装

    安装 ansible-server的安装 client需要有python2.5以上 的python server和client都关闭了selinux server端: 网址: http://www.a ...

  9. eclipse 修改中英文显示

    1.关闭eclipse 2.右键->选择属性--->打开文件位置 3.找到“eclipse.ini”文件,用EditPlus打开 4.在里面加 “-Duser.language=en”,即 ...

  10. Hessian服务端和客户端示例

    一.服务端 1.创建web项目,建立客户端调用的hessian接口和实现类. 接口: package com.ymx.hessian.service; import com.ymx.hessian.s ...