1.c++输入输出:
int n;
cin>>n;
cout<<n<<'\n';
2.万能头文件(包含很多用到的函数)
#include<bits/stdc++.h>
3.取消同步流(可以加速cin,cout带来的影响)
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
4.c++保留小数位
double a=3.1415926;
cout<<fixed<<setprecision(3)<<a<<'\n';//输出保留三位小数后的a
5.c++新定义
const int weekday1 = 7;
#define weekday2 = 8;
typedef long long ll;
using ll =long long;
6.快速计算星期几(由年月日算是周几)
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int y,m,d,w;
cin>>y>>m>>d;
if(m==1||m==2)
m=m+=12;
//一月,二月当成13,14算
w=(d+2*m+3*(m+1)/5+y+y/400+y/4-y/100)%7;
//算出来的w+1才是星期几
cout<<"今天是星期"<<w+1;
return 0;
}
7.bool类型
bool类型有两个输出值:
true(代表1,代表真)
false(代表0,代表假)
int t=0;
bool flag=true;
while(flag==true){
t=t+1;
if(t==6){
flag=false;
}
}
cout<<t;
8.读入带空格的字符串
//c读入带空格的字符串
char s1[15];
scanf("%[^\n]",s1);
//c++读入带空格的字符串
string s2;
getline(cin,s2);
9.一些容器(后面结合数据结构陆续整理出来)
vector:动态数组容器
pair:一对值的组合
set:存储不重复元素,集合
map:关联容器,存键值对
queue:先进先出队列
stack:后进先出为栈
10.存储单元换算
(1)位(bit):
信息的最小单位,2进制的一位即为1bit
1个bit有两种状态,0和1
(2)字节(Byte):
1KB=1024Byte
1MB=1024KB
1GB=1024MB
1TB=1024GB