c++语法
BHS_
间歇性学习,持续性摆烂
展开
-
专题一_栈与向量——栈
As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes a problem, there is only .原创 2022-04-04 10:04:25 · 237 阅读 · 0 评论 -
sstream_istringstream_stringstream
#包含三类:istringstream,ostringstream, stringstream分别对应输入,输出,输入和输出操作很强大的一个功能就是可以自动推导变量的类型The istringstream type reads a string, ostringstream writes a string, and stringstream reads and writes the string.##istringstream特性是::对象用于输入一行字符串,以 空格 为分隔符把该行分隔开来 *原创 2022-03-28 17:28:15 · 423 阅读 · 0 评论 -
c++对象和类距举例
#include<iostream>using namespace std;/*继承封装多态类的访问权限*/class bank_account{ public: //函数名与类名相同,就是构造函数,不能与有返回值(void返回值是空) //用于初始化,由系统调用 bank_account(int acc_num, double amount); void open(int acc_num,double amount);//开户 void deposite.原创 2022-03-28 14:52:42 · 746 阅读 · 0 评论 -
次佛锅_上海理工大学2022天梯选拔
链接:登录—专业IT笔试面试备考平台_牛客网来源:牛客网题目描述你好阿,穿越题目前来的选手众所周知backordinary不会次佛锅,所以邀请您来喂他。佛锅是一串包含大小写英文字母、数字、空格的字符串。每个食材用单词加数字的方式表示,代表这个食材有多少个,例如yaxin 1代表有1个yaxin。每个食材间用空格隔开,相同食材可能多次出现。backordinary每次会告诉你他想吃啥,需要你去锅里给他夹出来,他想知道每次他能吃到多少。输入描述:第一行长度为n的字符串,代表佛锅.原创 2022-03-26 19:02:15 · 1068 阅读 · 0 评论 -
取整函数_
#include<iostream>#include<cmath>using namespace std;int main(){ double num = 8.6; cout << num << " 向上取整为: " << ceil(num) << endl; cout << num << " 向下取整为: " << floor(num) << e.原创 2022-03-21 22:40:24 · 290 阅读 · 0 评论 -
数学函数&&随机数
三角函数#include<iostream>#include<cmath>#include<ctime>using namespace std;int main(){ //数学函数中注意的是sin(x),x指的是弧度值 //同样:: 越是精确,返回的结果越是精确 //也可以用流操作符可控制 cout << sin(3.1415926) << endl; cout << cos(3.14) <&.原创 2022-03-21 15:30:43 · 123 阅读 · 0 评论 -
函数重载_
最简单的返回最大值#include<iostream>using namespace std;//函数重载//不同的形式参数表,不同的返回值类型int max_fun(int a, int b){ if (a > b)return a; else return b;}double max_fun(double a, double b){ if (a > b)return a; else return b;}int main(){ .原创 2022-03-21 15:31:19 · 69 阅读 · 0 评论 -
map__
#include<iostream>#include<map>using namespace std;void text01(){ map<int, int>mymap; //map插入输出方式 //插入数据,first是key值,second是value值 //第一种 //mymap.insert(pair<int, int>(10, 10)); pair<map<int, int>::iterator, boo.原创 2022-03-20 20:46:07 · 361 阅读 · 0 评论 -
pair_对组
#include<iostream>#include<string>using namespace std;void text01(){ //pair定义输出 pair<int, int>pair1(10, 20); cout << pair1.first << ' ' << pair1.second << endl; pair<int, string>pair2(10, "aaa")...原创 2022-03-19 22:11:32 · 54 阅读 · 0 评论 -
set/multiset
set和multiset的特性是可以根据元素的值自动排序 ( 默认由小到大 ),set是以红黑树为底层机制,他的查找效率很好 ,set不允许重复元素出现,multiset允许重复元素出现;set只允许insert()操作,不支持,sort(),top()之类的但是支持swap(),size(),empty() #include<iostream>#include<set>using namespace ...原创 2022-03-19 20:27:16 · 1058 阅读 · 0 评论 -
queue_队列
注意的是几个容器的区分:对头只能出,队尾只能进;#include<iostream>#include<queue>using namespace std;void text01(){ queue<int>q; q.push(10); q.push(20); q.push(30); q.push(40); while (q.size() >0) { cout << q.front(...原创 2022-03-19 12:43:54 · 43 阅读 · 0 评论 -
stack()
栈不提供迭代器,不能遍历,不支持随机存取,只能通过top从栈顶获取和删除元素原创 2022-03-19 12:23:06 · 134 阅读 · 0 评论 -
deque_
前言:deque 时间效率低,一般deque 容器的赋值大小操作与vector相同deque 是两端开口,vector 是尾端开口;deque中元素的储存位置不一定连续,所以排序操作效率低,但是deque容器元素个数减小时,会自动进行内存减小,这也是vector 的不同之处。 deque也有size(),empty(),resize(),操作插入删除#include<iostream>#include<deque>...原创 2022-03-19 10:27:56 · 55 阅读 · 0 评论 -
vector
vector 容器的增查删改#include<iostream>#include<vector>using namespace std;//vector 输出void Print_vector(vector<int>& v){ //begin(),end();返回的是迭代器 for (vector<int>::iterator it = v.begin(); it != v.end(); it++) cout <..原创 2022-03-18 17:53:18 · 133 阅读 · 0 评论 -
#include<string> #include<cstring>
C++ strings//string input//string 类型可以直接比较string comparisonsstring str,str2;if(str>str2)if(str==str2)if(str<str2)//下图本是定义的时候,习惯写成了赋值initiallisation//字符串的赋值assingment//交换Swapping strings//string concatention...原创 2022-03-08 23:44:33 · 1719 阅读 · 0 评论 -
c++语法_manipulators(流操纵符)_iomanip
manipulatorssetw(int n) 域宽,就是列数,仅仅对紧跟其后的起作用;setfill(‘padding')将默认的空格填充字符换成padding;原创 2022-03-01 17:49:29 · 614 阅读 · 0 评论