1.vector

2.queue

3.stack

4.map

5.set

6.多组输入输出问题

详解见代码以及注释:

//学习STL的使用
#include <bits/stdc++.h>
using namespace std; int main(){
// 1.使用vector
// vector<int> v;//也可以vector<string类型>
// for(int i=0; i<=10; i++){
// v.push_back(i*i);//加入到vector中去
// }
// for(int i=0; i<v.size(); i++){//范围0~v.size()
// cout << v[i] << " ";//访问vector元素
// }
// cout << endl; // 2.使用queue
// queue<int> q;//定义一个空队列
// //先进先出
// q.push(1);//入队
// q.push(2);
// q.push(3);
// while( !q.empty() ){//队列不为空
// cout << q.front() << " ";//取出队首元素
// q.pop();//出队
// } // 3.使用stack栈
// stack<int> s;
// //后进先出
// s.push(1);
// s.push(2);
// s.push(3);
// while( !s.empty() ){
// cout << s.top() << " ";
// s.pop();
// } // 4.使用map(key-value)键值对
// map<string, int> dict;//定义一个map
// //key:string类型,value:int类型
// dict["tom"] = 1;//定义映射关系
// dict["jack"] = 2;
// dict["xiaxia"] = 6;
// if( dict.count("xiaxia") ){//如果存在"xiaxia",count("xiaxia")=true
// cout << "xiaxia is very" << dict["xiaxia"];
// }
// //使用迭代器遍历map的key和value
// map<string, int>::iterator it;//定义迭代器
// for(it=dict.begin(); it!=dict.end(); it++){
// cout << it->first << ":" << it->second << endl;
// }
// dict.clear();//清空map // 5.使用set
// set<string> s;
// s.insert("安徽");
// s.insert("陕西");
// s.insert("北京");
// s.insert("上海");
// set<string>::iterator it;
// for(it=s.begin(); it!=s.end(); it++){
// cout << *it << " ";
// }
// cout << endl;
// s.erase("北京");
// s.erase("上海");
// for(it=s.begin(); it!=s.end(); it++){
// cout << *it << " ";
// }
// cout << endl;
// if( s.count("陕西") ){
// cout << "陕西 I'm coming!" << endl;
// }
// s.clear();//清空set // 6.多组输入输出问题
// //6.1:C语言版
// int a, b;
// while( scanf("%d %d", &a, &b)!=EOF ){
// printf("%d", a+b);
// }
// //6.2:C++语言版
// int a, b;
// while( cin >> a >> b ){
// cout << a+b << endl;
// } return 0;
}

补充:多组输入输出问题:

《N诺机试指南》(三)STL使用的更多相关文章

  1. 《N诺机试指南》(二)C++自带实用函数

    1.排序sort函数: 2.查找:  实例:  3. 队列:

  2. 《N诺机试指南》(五)进制转化

    进制转化类题目类型: 代码详解及注释解答:  //进制转化问题 #include <bits/stdc++.h> using namespace std; int main(){ // 1 ...

  3. 《N诺机试指南》(七)排版类问题

    1.菱形问题: 解析: 主要通过打印空格和星形来打印整个图形,将整体分为=上三角形+下三角形 首先观察上三角形可以发现:第一行2个空格1个星.第二行1个空格3个星.第三行0个空格5个星     空格数 ...

  4. 《N诺机试指南》(一)数组妙用

    题目A: 大家思路有可能是这样: 将输入数据全部存储到一个数组里,然后可以冒泡排序一波,从小到大排序 那么怎么找到重复次数呢:我是这样想的,新定义数组b,原数组a,首先b[0] = a[0],定义指针 ...

  5. 《N诺机试指南》(八)日期、字符串、排序问题

    1.日期问题: 输入: 例题: 代码: #include <stdio.h> #include <bits/stdc++.h> struct node{ int year, m ...

  6. 机试指南第二章-经典入门-Hash的应用自解

    Hash的应用: Hash即散列,不像数据结构与算法中讲的各种Hash方法和冲突处理等过多的阐述,以下主要介绍Hash在机试试题解答中的作用. 例2.5 统计同成绩学生人数 Hash解法AC代码:(一 ...

  7. Hua Wei 机试题目三---2014

    一.根据对应规则进行翻译输出 描述:已知有如下的对应规则: ,则输入任意个正整数,输出经过规则翻译以后对应的结果. 例如:输入:1234:输出bcde. 题目很简单,我觉得需要注意的问题就是对于大整数 ...

  8. 王道机试指南题解(C/C++版)

    第 2 章 经典入门 一 排序 例 2.1 排序 代码 2.1 冒泡排序(时间复杂度 \(O(n^2)\)) #include <iostream> using std::cin; usi ...

  9. 2015 NI 校招笔试机试面试

    美国国家仪器NI也算是入驻上海很好的一家外企了,它是我们院的合作公司,加上今年NI在我们院扩招实习生,这次是一个难得的机会可以进入NI实习,可惜我并没有好好把握... 一.笔试 几个做错的印象特别深刻 ...

随机推荐

  1. Java AOP的底层实现原理

    Java AOP的底层实现原理 一.什么是AOP 1.AOP:Aspect Oriented Programming(面向切面编程),OOP是面向对象编程,AOP是在OOP基础之上的一种更高级的设计思 ...

  2. list绑定

    /** * 首页信息查询的回调函数 * @param 返回值 */ M_Main.ajaxCallBack = function (data){ var dataSource = data.resiC ...

  3. makefile个人理解

    makefile makefile抽象层面的理解 学习某一样东西之前一定要明确学习的目的,即学习了这项工具能解决一些什么问题,其优势是什么? makefile的优势就是能够动态根据文件的新旧来决定是否 ...

  4. .Net 面试题整理(一)

    1.C# 的三大特性? 封装.继承.多态 2.简述 private. protected. public. internal 修饰符的访问权限. private : 私有成员, 在类的内部才可以访问. ...

  5. bootstrapValidator JS修改内容无法验证

    需求: form表单输入中有坐标,坐标可以输入也可以从地图中获取,验证插件使用的是 bootstrapValidator 问题: 当输入错误的值时会触发验证,有错误提示.当在地图上选择坐标,通过js修 ...

  6. 用来更新服务的bat 脚本

    net stop XK.Service echo "已停止服务,开始更新!" set /a t = echo %t% :loop 127.1 >nul set /a t = ...

  7. 【5min+】闪电光速拳? .NetCore 中的Span

    系列介绍 简介 [五分钟的DotNet]是一个利用您的碎片化时间来学习和丰富.net知识的博文系列.它所包含了.net体系中可能会涉及到的方方面面,比如C#的小细节,AspnetCore,微服务中的. ...

  8. cogs 647. [Youdao2010] 有道搜索框 Trie树 字典树

    647. [Youdao2010] 有道搜索框 ★☆   输入文件:youdao.in   输出文件:youdao.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] 在有 ...

  9. JSON的学习与使用

    .katex { display: block; text-align: center; white-space: nowrap; } .katex-display > .katex > ...

  10. struts2 convention插件

    1.struts2自2.1以后推荐使用Convention Plugin支持struts零配置支持(引入jar:struts2-convention-plugin-2.x.x.jar)①convent ...