可能用到include
#include <iostream>
#include <algorithm>
using namespace std;
#include<string>
#include<queue>
#include<map>
#include "cstdio"
#include "cstring"
#include "cstdlib"
#include <stdio.h>
需要不断循环输入数据,一般用于最外层循环
while(scanf("%lf %d",&x,&n)!=EOF)
输入方式二;
cin>>count;
循环输入保存在数组中
for(int i=0;i<N;i++){
scanf("%d",&num[i]);
}
输出的y保留6位小数
printf("%.6lf\n",y);
输出方式二:
cout<<max<<' '<<min<<endl;
将字符串倒过来
reverse( s.begin(), s.end() );
字符串的长度
s.length()
len=strlen(input)
int size=str.size()-3;
字符串也可以用数组方式来取得其中第n个字符,如:input[n]
读取字符串另一种方式;
char s[10001],a[10001];
scanf("%d",&N);
getchar();
while(N--)
{
gets(s);
n=strlen(s);
}
浮点数计算应注意+0.5,修正误差
int sq=floor(sqrt(num[i]*1.0)+0.5);
翻转数组
int temp;
for (i = 0, j = k - 1; i < j; i ++, j --) {
temp = ten[i];
ten[i] = ten[j];
ten[j] = temp;
}
队列的使用
queue<str_step> Q; //队列,队列元素为(string,int)
while(!Q.empty())
Q.pop();//删除头部元素
Q.push(str_step(strtmp,st.step+1));
map的使用:
map<string,int> M; //查找所给字符串是否在集合中,若不在集合中则将新的
//结构体变量(移位字符串和移位次数)压入队列
//当然也可以不用map,开辟一个字符串数组也行,
//大小只要为2^13就可以了
if(M.find(strtmp)==M.end())
{
Q.push(str_step(strtmp,st.step+1));
M[strtmp]=size++;
}
将数组全部元素设置为0
memset(res, 0, sizeof(res));
两个普通矩阵相乘
M mul(M m, M n){
M t;
t.a = (m.a * n.a + m.b * n.c) % Mod;
t.b = (m.a * n.b + m.b * n.d) % Mod;
t.c = (m.c * n.a + m.d * n.c) % Mod;
t.d = (m.c * n.b + m.d * n.d) % Mod;
return t;
}
二分幂乘,用的时间短
M pow(){
m.a = m.d = 1;
m.b = m.c = 0;
//二分幂乘,求矩阵o的k次方
while(k){
if(k&1) m = mul(m,o);
o = mul(o,o);
k >>= 1;
}
return m;
}
如果a!=b,返回a,否则返回b
return (a != b) ? a : b;
重载运算符
Complex Complex::operator+(int x)
{
return Complex(real+x,imag);
}
开方(需要#include<math.h>或<cmath.h>)
sqrt(x);
升序排序(需要#include<algotithn>)
sort(s.begin,s.end)
文件读写(需要#include<fstream>)
ofstream out("sf1.txt");
out<<s.name<<" "<<s.age<<" "<<endl;
ifstream in("sf1.txt");
in>>st[i].name>>st[i].age>>endl;