ACM整理(一)——所需函数

 

可能用到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;


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值