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. 手机cpu结构,arm

    问题描述 今天测试人员测试集成版本时除了一个bug:关于华为 Mate 8手机Android 6.0系统运行刚刚提测的版本时,出现闪退的bug,而小米 4 手机Android 6.0系统却没有出现任何 ...

  2. accp8.0转换教材第1章多线程理解与练习

    一.单词部分: ①process进程 ②current当前的③thread线程④runnable可获取的 ⑤interrupt中断⑥join加入⑦yield产生⑧synchronize同时发生 二.预 ...

  3. 浅谈angular中的promise

    promise目的就是为了跳出回调地狱.老掉牙的东西,大神轻拍. 举个最简单的例子:请求数据(getData),解析数据(executeData),显示数据(showData). //获取数据 fun ...

  4. ssh自动化出现的莫名报错

    代码如: ssh -q user@host <<EOF localhost EOF 会出现提示如: Pseudo-terminal will not be allocated becaus ...

  5. CSS3-loading动画(一)

    前两天从一个网站中看到了一些比较好的loading动画效果,是用纯CSS3来写的,感觉不错,就尝试着照着效果来自己写出来. 在开始之前,先复习一个小知识:CSS3新增的关键帧动画,可以用来实现很多的动 ...

  6. (cljs/run-at (JSVM. :all) "一次说白DataType、Record和Protocol")

    前言  在项目中我们一般会为实际问题域定义领域数据模型,譬如开发VDOM时自然而言就会定义个VNode数据类型,用于打包存储.操作相关数据.clj/cljs不单内置了List.Vector.Set和M ...

  7. Unity3D调用摄像头

    代码启用摄像头 .using UnityEngine;   .using System.Collections;   .   .public class WebCamManager : MonoBeh ...

  8. virtualbox 安装centos系统,设置双网卡实现虚拟机上网及主宿互访

    写在前面:前两天想玩linux,在VMware中装了centos,进入系统后发现连不上网,搜了下教程,/etc/sysconfig/network-scripts/目录下没有 ifcfg-e*的文件 ...

  9. TCP简单通讯

    客户端代码: package com.kaige123.net01; import java.io.IOException; import java.io.InputStream; import ja ...

  10. python中的判断语句与循环语句

    if语句 每条if语句的核心都是一个值为Ture或False的表达式,这种表达式被称为为条件测试.if语句检查程序当前状态,并据此采取相应的措施.如果条件测试的值为Ture,Python就执行紧跟在i ...