写在前面:本文章使用devc++,若用VC的别进来!
如果你不知道怎么写库,请参考我这篇文章:手把手教你建立c++个人库
在新建好库文件之后,我们就可以开始写库了。
在写函数时有这样几条建议:
1.千万不要写有人写过的函数。
2.函数名字首字母大写或全大写
3.函数名在保证能表达内容的情况下尽量简写
4.要在文件头写上库的简介
5.尽量不要用别人写好的东西(例如sort())
还是老规矩,上代码
//KeatsLi's header files
#include<iostream>
#include<cstring>
#include<ctime>
using namespace std;
//math
long long gcd(long long a,long long b){
long long r;
while(b>0){
r=a%b;
a=b;
b=r;
}
return a;
}
int py_random(int low,int high){
srand((unsigned)time(0));
return rand()%(high-low)+low;
}
//str
char Storage[100010];
char *str_to_chr(string readlist){
memset(Storage,0,sizeof(Storage));
for(int i=0;i<readlist.length();i++){
Storage[i]=readlist[i];
}
return Storage;
}
long long qread(const string type){//若需从文件读入,请freopen
if(type=="%d"){
int y=1;
int ans=0;
char t=getchar();
while(t<'0'||t>'9'){
if(t=='-'){
y=-1;
}
t=getchar();
}
while(t!='\n'){
ans*=10;
ans+=t-'0';
t=getchar();
}
return ans;
}
else if(type=="%lld"){
int y=1;
long long ans=0;
char t=getchar();
while(t<'0'||t>'9'){
if(t=='-'){
y=-1;
}
t=getchar();
}
while(t!='\n'){
ans*=10;
ans+=t-'0';
t=getchar();
}
return ans;
}
else{
char t=getchar();
return t;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)