《ACM算法详解》— ACM 头文件大全 常用函数

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复制到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的内容清空再复制。

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中的所有字符置于一个给定的字符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>

 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转换成双精度数,并返回这个数,错误返回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


 

  • 6
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值