ACM 头文件大全 常用函数

来源:互联网 发布:亚洲蹲 知乎 编辑:程序博客网 时间:2024/05/22 01:33
ACM   头文件大全    常用函数
#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复制到destchar  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的内容清空再复制。size_t strcspn(const char *s1,constchar *s2)   ?aomeiaga  eitrtr返回3 即e 在s1中的位置。== char  strpbrk(const char *s1,const char *s2)== size_t strspn(const char *s1,const char*s2)    扫描s1  返回字符串s1中第一个在s2中出现的字符在s1中的下标值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中的所有字符置于一个给定的字符chchar  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.hint isalpha(char ch)  若ch是字母('A'-'Z','a'-'z')返回非0值,(返回1024)否则返回0int isalnum(char ch)  若ch是字母('A'-'Z','a'-'z')或数字('0'-'9')                     返回非0值,否则返回0int isascii(char ch)  若ch是字符(ASCII码中的0-127)返回非0值,否则返回0int iscntrl(char ch)  若ch是作废字符(0x7F)或普通控制字符(0x00-0x1F)                     返回非0值,否则返回0int isdigit(char ch) 若ch是数字('0'-'9')返回非0值,否则返回0int isgraph(char ch)  若ch是可打印字符(不含空格)(0x21-0x7E)返回非0值,否则返回0int islower(char ch)  若ch是小写字母('a'-'z')返回非0值,否则返回0int isupper(char ch)  若ch是大写字母('A'-'Z')返回非0值,否则返回0 int isprint(char ch)  若ch是可打印字符(含空格)(0x20-0x7E)返回非0值,否则返回0int ispunct(char ch)  若ch是标点字符(0x00-0x1F)返回非0值,否则返回0int isspace(char ch)  若ch是空格(' '),水平制表符('\t'),回车符('\r'),走纸换行('\f'),垂直制表符('\v'),换行符('\n')  返回非0值,否则返回0int isxdigit(char ch) 若ch是16进制数('0'-'9','A'-'F','a'-'f')返回非0值,  否则返回0int 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> cout<<number;double atoi(char *nptr)     将字符串nptr转换成整数并返回这个整数double atol(char *nptr)      将字符串nptr转换成长整数并返回这个整数double atof(char *nptr)           将字符串nptr转换成浮点数并返回这个浮点数 // #include<stdlib.h>double atof(char *nptr) 将字符串nptr转换成双精度数,并返回这个数,错误返回0double 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.hint 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+y2double 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.9M = mod(X,Y)   返回X对Y取模运算的结果。这里X可以是一个数组。其中,比较特殊的情况有:mod(X,0):结果为Xmod(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



1 0