文章目录
getchar()
getchar()//输入字符
#include<bits/stdc++.h>
using namespace std;
char a;
int main(){
a=getchar();
cout<<a;
return 0;
}
putchar()
putchar()//输出字符
#include<bits/stdc++.h>
using namespace std;
char a;
int main(){
a=getchar();
putchar(a);
return 0;
}
getline(cin,)
getline(cin,);//输入整行字符串
#include<bits/stdc++.h>
using namespace std;
string a;
int main(){
getline(cin,a);
cout<<a;
return 0;
}
gets()
gets()//字符数组输入函数
#include<bits/stdc++.h>
using namespace std;
char a[105];
int main(){
gets(a);
puts(a);
return 0;
}
puts()
puts()//字符数组输出函数
#include<bits/stdc++.h>
using namespace std;
char a[105];
int main(){
gets(a);
puts(a);
return 0;
}
strlen()
strlen();//获取字符数组的长度
#include<bits/stdc++.h>
using namespace std;
char a[105];
int len;
int main(){
cin>>a;
len=strlen(a);
cout<<len;
return 0;
}
Sleep()
Sleep()//停留多少毫秒
#include<bits/stdc++.h>
#include<windows.h>//sleep()函数的头文件
using namespace std;
char a[105];
int len;
int main(){
cin>>a;
Sleep(1000);//停留1000毫秒
cout<<a;
return 0;
}
unique(,)
unique(,)//去除重复元素,要有头文件#include
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int n,a[105];
int main(){
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
int t=unique(a+1,a+n+1)-a;
cout<<t;
return 0;
}
sin()
sin()//数学里的正弦函数。参数的单位是度。
#include<bits/stdc++.h>
using namespace std;
int a;
int main(){
cin>>a;
cout<<sin(a);
return 0;
}
cos()
cos()//数学里的余弦函数。参数的单位是度。
#include<bits/stdc++.h>
using namespace std;
int a;
int main(){
cin>>a;
cout<cos(a);
return 0;
}
tan()
tan()//该函数返回弧度角(double 型)的正切。
#include<bits/stdc++.h>
using namespace std;
int a;
int main(){
cin>>a;
cout<<tan(a);
return 0;
}
log()
log()//该函数返回参数的自然对数。
#include<bits/stdc++.h>
using namespace std;
int a;
int main(){
cin>>a;
cout<<log(a);
return 0;
}
log2()
log2()//求以2为底的对数函数值
#include<bits/stdc++.h>
using namespace std;
int a;
int main(){
cin>>a;
cout<<log2(a);
return 0;
}
log10()
log10()//求以10为底的对数函数值
#include<bits/stdc++.h>
using namespace std;
int a;
int main(){
cin>>a;
cout<<log10(a);
return 0;
}
hypot(,)
hypot(,)//该函数返回两个参数的平方总和的平方根,参数为一个直角三角形的两个直角边,函数会返回斜边的长度。
#include<bits/stdc++.h>
using namespace std;
int x,y;
int main(){
cin>>x>>y;
cout<<hypot(x,y);
return 0;
}
abs()
abs()//返回整型参数的绝对值
#include<bits/stdc++.h>
using namespace std;
int a;
int main(){
cin>>a;
cout<<abs(a);
return 0;
}
fabs()
fabs()//返回双精度参数的绝对值
#include<bits/stdc++.h>
using namespace std;
double a;
int main(){
cin>>a;
cout<<fabs(a);
return 0;
}
ceil()
ceil()//返回不小于参数的最小整数(上取整)
#include<bits/stdc++.h>
using namespace std;
double a;
int main(){
cin>>a;
cout<<ceil(a);
return 0;
}
floor()
floor()//返回不大于参数的最大整数(下取整)
#include<bits/stdc++.h>
using namespace std;
double a;
int main(){
cin>>a;
cout<<floor(a);
return 0;
}
pow(,)
pow(,) //返回x的y次幂的值
#include<bits/stdc++.h>
using namespace std;
int x,y;
int main(){
cin>>x>>y;
cout<<pow(x,y);
return 0;
}
sqrt()
sqrt()//返回参数的平方根
#include<bits/stdc++.h>
using namespace std;
int a;
int main(){
cin>>a;
cout<<sqrt(a);
return 0;
}
cin.sync()
cin.sync();//清除cin造成的缓冲区
#include<bits/stdc++.h>
using namespace std;
int a;
int main(){
cin.sync();
cin>>a;
cout<<a;
return 0;
}
memset(,)
memset(x,y,z)//将x中的每个数都变成y,z是x的长度
#include<bits/stdc++.h>
using namespace std;
int z,x[105],y;
int main(){
cin>>z;
for(int i=1;i<=z;i++)cin>>x[i];
cin>>y;
memset(x,y,z);
return 0;
}
memcpy(,)
memcpy(d,s+14,4)//将s中第14个字符开始的4个连续字符复制到d中。(从0开始)
#include<bits/stdc++.h>
using namespace std;
char s[105]="Hello My name is Justa",d[105];
int main(){
memcpy(d,s+14,4);
cout<<d;
return 0;
}
reverse(,)
reverse(x,x+y)//在区间[x,y)内的元素反转
#include<bits/stdc++.h>
using namespace std;
int n,x,y,a[105];
int main(){
cin>>n>>x>>y;
for(int i=1;i<=n;i++)cin>>a[i];
reverse(x,x+y);
for(int i=1;i<=n;i++)cout<<a[i]<<" ";
return 0;
}
fmod(,)
fmod(x,y)//计算x对y的模
#include<bits/stdc++.h>
using namespace std;
int x,y;
int main(){
cin>>x>>y;
cout<<fmod(x,y);
return 0;
}
strcat(,)
strcat(x,y)//把x接到y的后面
#include<bits/stdc++.h>
using namespace std;
string x,y;
int main(){
cin>>x>>y;
cout<<strcat(x,y);
return 0;
}
.insert(,)
x.insert(a,b)//在x的第a个位置插入b
#include<bits/stdc++.h>
using namespace std;
string x,b;
int a;
int main(){
cin>>x>>a>>b;
x.insert(a,b);
cout<<x;
return 0;
}
.substr(,)
x.substr(a,b)//在x的第a个位置取b个字符
#include<bits/stdc++.h>
using namespace std;
string x,d;
int a,b;
int main(){
cin>>x>>a>>b;
d=x.substr(a,b);
cout<<d;
return 0;
}
.erase(,)
x.erase(a,b)//在x的第a个位置删b个字符
#include<bits/stdc++.h>
using namespace std;
string x;
int a,b;
int main(){
cin>>x>>a>>b;
x.erase(a,b);
cout<<x;
return 0;
}
replace(,)
x.replace(a,b,c)//在x的第a个位置删b个字符 ,替换成c
#include<bits/stdc++.h>
using namespace std;
string x,c;
int a,b;
int main(){
cin>>x>>a>>b>>c;
x.replace(a,b,c);
cout<<x;
return 0;
}
.find(,)
x.find(a,b)//在x的第b个字符查找a的位置,找不到则返回string::npos
#include<bits/stdc++.h>
using namespace std;
string x,a;
int b;
int main(){
cin>>x>>a>>b;
cout<<x.find(a,b);
return 0;
}
fill(,)
fill(x+1,x+n+1,d)//将x+1到x+n+1的数都变成d
#include<bits/stdc++.h>
using namespace std;
int n,x,d,a[105];
int main(){
cin>>n>>x>>d;
for(int i=1;i<=n;i++) cin>>a[i];
fill(x+1,x+n+1,d);
return 0;
}
isupper()
isupper()//判断是否大写
#include<bits/stdc++.h>
using namespace std;
char n;
int main(){
cin>>n;
if(isupper(n)) cout<<"YES";
else cout<<"NO";
return 0;
}
islower()
islower()//判断是否小写
#include<bits/stdc++.h>
using namespace std;
char n;
int main(){
cin>>n;
if(islower(n)) cout<<"YES";
else cout<<"NO";
return 0;
}
strlwr()
strlwr(x)//将x中的大写字母变小写字母
#include<bits/stdc++.h>
using namespace std;
char x[105];
int main(){
cin>>x;
strlwr(x);
return 0;
}
strupr()
strupr(x)//将x中的大写字母变小写字母
#include<bits/stdc++.h>
using namespace std;
char x[105];
int main(){
cin>>x;
strupr(x);
return 0;
}
setw()
setw()//设置场宽
#include<bits/stdc++.h>
using namespace std;
int main(){
for(int i=1;i<=10;i++)
cout<<setw(10)<<i;
return 0;
}