ACM头文件、常用函数、宏定义
2017-07-25 14:45
423 查看
部分转载自:http://blog.csdn.net/liujiuxiaoshitou/article/details/69920917
头文件
#include<assert.h>//设定插入点 #include <ctype.h>//字符处理 #include<errno.h>//定义错误码 #include <float.h>//浮点数处理 #include<fstream.h>//文件输入/输出 #include<iomanip.h> //参数化输入/输出 #include<iostream.h>//数据流输入/输出 #include<limits.h> //定义各种数据类型最值常量 #include<locale.h> //定义本地化函数 #include<math.h> //定义数学函数 #include<stdio.h> //定义输入/输出函数 #include<stdlib.h> //定义杂项函数及内存分配函数 #include<string.h> //字符串处理 #include<strstrea.h>//基于数组的输入/输出 #include<time.h> //定义关于时间的函数 #include<wchar.h> //宽字符处理及输入/输出 #include<wctype.h> //宽字符分类 标准 C++ (同上的不再注释) #include<algorithm>//ST通用算法 #include <bitset> //STL 位集容器 #include<cctype> #include<cerrno> #include<clocale> #include<cmath> #include<complex> //复数类 #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> #include<deque>//STL双端队列容器 #include<exception>//异常处理类 #include <fstream> #include<functional> //STL 定义运算函数(代替运算符) #include<limits> #include<list> //STL 线性列表容器 #include<map> //STL 映射容器 #include<iomanip> #include<iOS> //基本输入/输出支持 #include<iosfwd> //输入/输出系统使用的前置声明 #include<iostream> #include<istream>//基本输入流 #include <ostream>//基本输出流 #include<queue>//STL 队列容器 #include <set> //STL 集合容器 #include<sstream>//基于字符串的流 #include <stack> //STL 堆栈容器 #include<stdexcept> //标准异常类 #include<streambuf>//底层输入/输出支持 #include<string>//字符串类 #include<utility>//STL 通用模板类 #include<vector> //STL 动态数组容器 #include<cwchar> #include<cwctype>
常用函数
str…字符串操作函数 char ch[ ] 进行操作。 size_t strlen(const char *s) 返回字符串s的长度 char strlwr(char *s) 返回指向s的指针。 //不能用 将字符串s中的大写字母全部转换成小写字母,并返回转换后的字符串 char strupr(char *s) //不能用 将字符串s中的小写字母全部转换成大写字母,并返回转换后的字符串 char stpcpy(char *dest,const char *src) 将字符串src复制到dest char strcat(char *dest,const char *src) 将字符串src添加到dest末尾 char strchr(const char *s,int c) 检索并返回字符c在字符串s中第一次出现的位置//cout<<strchr(ch,'c');输出c及后面的字符串,返回指针类型。 int strcmp(const char *s1,const char *s2) 比较字符串s1与s2的大小,并返回s1-s2 char strcpy(char *dest,const char *src) 将字符串src复制到dest //会将dest的内容清空再复制。 char strncat(char *dest,const char *src,size_t maxlen) 将字符串src中最多maxlen个字符复制到字符串dest中,放在dest的后面 int strncmp(const char *s1,const char *s2,size_t maxlen) 比较字符串s1与s2中的前maxlen个字符 char strncpy(char *dest,const char *src,size_t maxlen) 复制src中的前maxlen个字符到dest中 strrev(char *s) //倒置,不能用 将字符串s中的字符全部颠倒顺序重新排列,并返回排列后的字符串 char strset(char *s,int ch) //不能用。 将一个字符串s中的所有字符置于一个给定的字符ch char strstr(const char *s1,const char *s2) 扫描字符串s2,并返回第一次出现s1的位置 //s1是s2的子串。返回此位置指针。 char strtok(char *s1,const char *s2) 检索字符串s1,该字符串s1是由字符串s2中定义的定界符所分隔 //返回s2之前的字符串。,s2不在s1则输出s1. /* * * 分类函数, 所在函数库为ctype.h * * */ int isalpha(char ch) 若ch是字母('A'-'Z','a'-'z')返回非0值,(返回1024)否则返回0 int isalnum(char ch) 若ch是字母('A'-'Z','a'-'z')或数字('0'-'9')返回非0值,否则返回0 int isascii(char ch) 若ch是字符(ASCII码中的0-127)返回非0值,否则返回0 int iscntrl(char ch) 若ch是作废字符(0x7F)或普通控制字符(0x00-0x1F)返回非0值,否则返回0 int isdigit(char ch) 若ch是数字('0'-'9')返回非0值,否则返回0 int isgraph(char ch) 若ch是可打印字符(不含空格)(0x21-0x7E)返回非0值,否则返回0 int islower(char ch) 若ch是小写字母('a'-'z')返回非0值,否则返回0 int isupper(char ch) 若ch是大写字母('A'-'Z')返回非0值,否则返回0 int isprint(char ch) 若ch是可打印字符(含空格)(0x20-0x7E)返回非0值,否则返回0 int ispunct(char ch) 若ch是标点字符(0x00-0x1F)返回非0值,否则返回0 int isspace(char ch) 若ch是空格(' '),水平制表符('\t'),回车符('\r'), 走纸换行('\f'),垂直制表符('\v'),换行符('\n') 返回非0值,否则返回0 int isxdigit(char ch) 若ch是16进制数('0'-'9','A'-'F','a'-'f')返回非0值, 否则返回0 int tolower(char ch) 若ch是大写字母('A'-'Z')返回相应的小写字母('a'-'z') int toupper(char ch) 若ch是小写字母('a'-'z')返回相应的大写字母('A'-'Z') int _tolower(char ch) 返回ch相应的小写字母('a'-'z') int _toupper(char ch) 返回ch相应的大写字母('A'-'Z') int toascii(char c) 返回c相应的ASCII 将string转换成int。(float)类似。 stringtext = "152"; intnumber = atoi( text.c_str() ); /* * * #include<stdlib.h> * * */ double atoi(char *nptr) 将字符串nptr转换成整数并返回这个整数 double atol(char *nptr) 将字符串nptr转换成长整数并返回这个整数 double atof(char *nptr) 将字符串nptr转换成浮点数并返回这个浮点数 /* * * #include<stdlib.h> * * */ double atof(char *nptr) 将字符串nptr转换成双精度数,并返回这个数,错误返回0 double strtod(char *str,char **endptr)将字符串str转换成双精度数,并返回这个数, cout<<strtod(str,NULL); sscanf(c, "%d", &a ); //将c字符串转换成整数赋给a. sscanf(c, "%f", &f ); //将c字符串转换成float赋给f. sprintf(c, "%d", a); //将整数a转换成字符串到c 数学函数,所在函数库为math.h、stdlib.h、string.h、float.h int abs(int i) (double i) 头文件需要用cmath) 返回整型参数i的绝对值 double cabs(struct complex znum) 返回复数znum的绝对值 double fabs(double x) 返回双精度参数x的绝对值 long labs(long n) 返回长整型参数n的绝对值 double exp(double x) 返回指数函数ex的值 double frexp(double value,int *eptr) 返回value=x*2n中x的值,n存贮在eptr中 double ldexp(double value,int exp); 返回value*2exp的值 double log(double x) 返回logex的值 double log10(double x) 返回log10x的值 10可改成任意数 double pow(double x,double y) 返回x^y的值 double pow10(int p) 返回10^p的值 double sqrt(double x) 返回的值 double cos(double x) 返回x的余弦cos(x)值,x为弧度 double sin(double x) 返回x的正弦sin(x)值,x为弧度 double tan(double x) 返回x的正切tan(x)值,x为弧度 double acos(double x) 返回x的反余弦cos-1(x)值,x为弧度 double asin(double x) 返回x的反正弦sin-1(x)值,x为弧度 double atan(double x) 返回x的反正切tan-1(x)值,x为弧度 double atan2(double y,double x) 返回y/x的反正切tan-1(x)值,y的x为弧度 double cosh(double x) 返回x的双曲余弦cosh(x)值,x为弧度 double sinh(double x) 返回x的双曲正弦sinh(x)值,x为弧度 double tanh(double x) 返回x的双曲正切tanh(x)值,x为弧度 double hypot(double x,double y) 返回直角三角形斜边的长度(z), x和y为直角边的长度,z2=x2+y2 double ceil(double x) 返回不小于x的最小整数 double floor(double x) 返回不大于x的最大整数 double modf(double value,double *iptr)?将双精度数value分解成尾数和阶? double fmod(double x,double y)返回x/y的余数 fmod(5.2,3.3)=1.9 M = mod(X,Y) 返回X对Y取模运算的结果。这里X可以是一个数组。 其中,比较特殊的情况有: mod(X,0):结果为X mod(X,X):结果为0 对字符串的输入问题 #include<stdio.h> 字符数组 char s[20]; gets(s); cout<<s; 字符串 string s; getline(cin,s);
1 保留小数点后两位 #include <iomanip> cout << setiosflags(ios::fixed) << setprecision(2)<< getAdd(num) << endl; 2 截取字符串 类似spilt #include <string> const char * spilt="/"; char *p; p=strtok(str,spilt); while(p!=NULL) { //cout << p << endl; num[i++]=atoi(p); p=strtok(NULL,spilt); } 3 自动排序 sort函数 #include<algorithm> #include<vector> sort(Rs.begin(),Rs.end()); sort(Rs.begin(),Rs.end(),greater<double>()); 4 开方函数 #include<cmath> return 2*sqrt(R*R-b*b/4); 5断点调试 cout << "cout%len " << count%len << ' ' << "num " << num << endl; 6基本格式 #include <iostream> using namespace std; int main() { int count; while(cin >> count) { } return 0; } 7 关于排序 bool cmp(int a,int b) { return abs(a)>abs(b); } sort(vec.begin(),vec.end(),cmp); 8 求字符串长度 strlen(str) 9 cin.getline(字符指针,字符个数N,结束符); //结束符(默认的是以'\n'结束) while(cin.getline(a,100)) 10 字符串比较 //strcmp(字符串1,字符串2) //s1<s2 <0 ; s1=s2 0 ;s1>s2 >0</pre>
宏定义
#define lson 2*i #define rson 2*i+1 #define LS l,mid,lson #define RS mid+1,r,rson #define UP(i,x,y) for(i=x;i<=y;i++) #define DOWN(i,x,y) for(i=x;i>=y;i--) #define MEM(a,x) memset(a,x,sizeof(a)) #define W(a) while(a) #define gcd(a,b) __gcd(a,b) #define LL long long #define MAX 1000005 #define MOD 1000000007 #define INF 0x3f3f3f3f #define EXP 1e-8 #define lowbit(x) (x&-x) #define lson 2*i #define rson 2*i+1 #define LS l,mid,lson #define RS mid+1,r,rson #define UP(i,x,y) for(i=x;i<=y;i++) #define DOWN(i,x,y) for(i=x;i>=y;i--) #define MEM(a,x) memset(a,x,sizeof(a)) #define W(a) while(a) #define gcd(a,b) __gcd(a,b) #define pi acos(-1.0) #define pii pair<int,int> #define LL long long #define MAX 1000005 #define MOD 1000000007 #define INF 0x3f3f3f3f #define EXP 1e-8 #define lowbit(x) (x&-x) ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);} ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int Scan() //输入外挂 { int res=0,ch,flag=0; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch<='9') res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res; } void Out(int a) //输出外挂 { if(a>9) Out(a/10); putchar(a%10+'0'); }
我的头文件
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <ctype.h>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <climits>
#include <string>
#include <list>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <sstream>
using namespace std;
#define lson 2*i
#define rson 2*i+1
#define LS l,mid,lson
#define RS mid+1,r,rson
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define pi acos(-1.0)
#define pii pair<int,int>
#define LL long long
#define MAX 1000005
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EXP 1e-8
#define lowbit(x) (x&-x)
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int Scan() //输入外挂 { int res=0,ch,flag=0; if((ch=getchar())=='-') flag=1; else if(ch>='0'&&ch<='9') res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res; } void Out(int a) //输出外挂 { if(a>9) Out(a/10); putchar(a%10+'0'); }
相关文章推荐
- 常用的头文件和函数
- OC常用的数学函数及宏定义
- c++常用函数所在头文件一览
- 常用函数对应的头文件
- Cocos2dx 常用函数和宏定义
- stdlib.h头文件下的常用函数
- 10-08常用的TIME和DATE函数以及各个函数对应的头文件
- 做ACM常用的C++头文件!
- c++常用函数所在头文件一览
- c++常用函数所在头文件一览
- 常用函数对应的头文件
- MTK编程起步——常用函数及宏定义
- ACM/ICPC 常用函数---strstr()字符串查找函数
- Linux内核开发常用函数及其头文件
- iomanip头文件常用函数汇总
- 总结一些在acm中常用的小技巧,小函数
- 常用函数对应的头文件
- [ACM]常用工具函数整理
- ACM杂记(技巧/注意事项/常用函数)
- cocos2dx 常用函数和宏定义