
c++基础
饮酒在风里
这个作者很懒,什么都没留下…
展开
-
不同进制之间的转换(c++)
#include <iostream>using namespace std;int main(){ int a,b,c; //p进制数转换为q进制数 先将p进制数转化为10进制数再转化为q进制数 cin>>a>>b;//将b进制数转a化为十进制数d int d=0,flag=1; while(a!=0)...原创 2019-03-01 16:57:24 · 591 阅读 · 0 评论 -
堆排序&&模拟堆排序
838. 堆排序输入一个长度为n的整数数列,从小到大输出前m小的数。输入格式第一行包含整数n和m。第二行包含n个整数,表示整数数列。输出格式共一行,包含m个整数,表示整数数列中前m小的数。数据范围1≤m≤n≤1051≤m≤n≤105,1≤数列中元素≤1091≤数列中元素≤109输入样例:5 34 5 1 3 2输出样例:1 2 3#i...原创 2019-09-19 21:43:20 · 231 阅读 · 0 评论 -
离散化-求区间和
假定有一个无限长的数轴,数轴上每个坐标上的数都是0。现在,我们首先进行 n 次操作,每次操作将某一位置x上的数加c。近下来,进行 m 次询问,每个询问包含两个整数l和r,你需要求出在区间[l, r]之间的所有数的和。输入格式第一行包含两个整数n和m。接下来 n 行,每行包含两个整数x和c。再接下里 m 行,每行包含两个整数l和r。输出格式共m行,每行输出一个询问中所...原创 2019-09-14 22:17:26 · 181 阅读 · 0 评论 -
大数乘法-大数除法模板(高精度)
乘法#include <iostream>#include <cstring>#include <cstdio>#include <queue>#include <cmath>#include <algorithm>#include <vector>using namespace std;#d...原创 2019-09-13 16:35:19 · 267 阅读 · 0 评论 -
大数加法-大数减法模板(高精度)
高精度加法#include <iostream>#include <cstring>#include <cstdio>#include <queue>#include <cmath>#include <algorithm>#include <vector>using namespace std;...原创 2019-09-13 13:47:32 · 183 阅读 · 0 评论 -
c++流操纵算子基础 简单数字输入输出样例(控制小数点前后位数等)
c++流操纵算子基础 简单数字输入输出(控制小数点前后位数等)所需头文件为 #include 1在这里插入代码片#include#includeusing namespace std;int main(){int n=141;//分别以十六进制/十进制/八进制先后输出 n;cout&amp;lt;&amp;lt;&quot;1)&quot;&amp;lt;&amp;lt;hex原创 2018-09-21 17:11:49 · 492 阅读 · 0 评论 -
c++ string类 流处理(字符串的输入输出和基础函数简介)
使用string 类需要包含头文件:#include<string>初始化方法:#include<iostream>#include<string>using namespace std;int main(){ string s1("hello"); string month="March"; string s2(8,'x'...原创 2018-09-22 18:03:08 · 11847 阅读 · 0 评论 -
数据结构 顺序队列 循环队列 基本操作
顺序队列基本操作:#define MAXSIZE 1000struct queue{ int front ,rear;//表示头指针和 尾指针 int data[MAXSIZE]; //存储数据的数组}void Initqueue(queue &q){ //初始化队列 q.front=0; q.rear;}bool Empty(queue &q...原创 2018-09-24 20:50:45 · 569 阅读 · 0 评论 -
栈的基本操作 c++
#define MAXSIZE 1000struct stack{ int data[MAXSIZE]; //存储数据的数组 int top; //栈顶}bool empty(stack &s){ return s.top==0; //判断栈是否为空}bool full(stack &s){ return ...原创 2018-09-26 22:15:08 · 1138 阅读 · 0 评论 -
设置种子生成随机数
#include <iostream>#include <ctime>#include <cstdlib>using namespace std;int main(){ int i,j;//设置种子 int t; while(cin>>t) { srand((unsigned)time(NULL)...原创 2018-11-15 21:02:09 · 587 阅读 · 0 评论 -
c++ 与数和字符有关的函数
1 double cos(double); 该函数返回弧度角(double 型)的余弦。 2 double sin(double); 该函数返回弧度角(double 型)的正弦。 3 double tan(double); 该函数返回弧度角(double 型)的正切。 4 double log(double); 该函数返回参数的自然对数。...转载 2018-11-26 20:54:33 · 191 阅读 · 0 评论 -
C++用函数交换两个变量的值
#include<iostream>using namespace std;void swap(int *x,int *y)//利用指针{ int temp; temp=*x; *x=*y; *y=temp;}void superswap(int &a,int &b)//通过引用{ int t; t=a; a=b; b=t;}i...原创 2018-12-23 20:54:52 · 7056 阅读 · 3 评论 -
哈希has散列-字符串hash
维护一个集合,支持如下几种操作:“I x”,插入一个数x; “Q x”,询问数x是否在集合中出现过;现在要进行N次操作,对于每个询问操作输出对应的结果。输入格式第一行包含整数N,表示操作数量。接下来N行,每行包含一个操作指令,操作指令为”I x”,”Q x”中的一种。输出格式对于每个询问指令“Q x”,输出一个询问结果,如果x在集合中出现过,则输出“Yes”,否则输出“...原创 2019-09-22 13:34:34 · 634 阅读 · 0 评论