c++知识总结(pat乙级)

1.isdigit()判断字符是否为数字字符?
2.isalpha()判断字符是否为字母
3.对字符串,从第i个位置开始,插入k个j
4.根据字符串中的字符,按照降序排列
5.将字符串转化为数字
6.将数字转化为字符串
7.对于vector定义的数组连续竖着for输入需要指明数组长度
8.s.substr()截取字符串的字符
9.toupper()将小写字母转化成大写字母
10.a.find(b)查找a字符串中是否含有b
11.int位数(4个字节,32位),long long位数(8个字节,64位)
12.tolower ,toupper, isalpha, isalnum, islower,isupper用法:
13.a.append(n,c)表示对字符串a的尾部添加n个字符c
14.reverse(a.begin(),a.end()) 对字符串a进行倒转
15.用vector将数组按照递减排序
16.用vector设置二维数组
17.用vector嵌套一个字符串数组
18.用getline接受一个带空格的字符串
19.给字符串压栈
20.将字符数组a以浮点数的方式保存到temp中,再将temp保留2位小数输出到字符数组b中
21.自定义cmp,对结构数组进行排序
22.关于scanf("\n")与scanf(" ")的讨论
23.set中的find
24.求最大公约数—辗转相除法
25.scanf在for中的一些输入
26.设置指定长度的字符串
27.设置一个3个线性表的vector数组:
28.设置结构数组:
29.将数字转化为字符串:
30.如果用cin输入数字,紧接用getline输入,必须在二者之间加入getchar(),否则就在输入完数字后程序结束
31.isalnum)用来判断字符是数字或者字母?是,返回true;否则,返回false
32.对于vector结构中有3个成员,对于特殊排序的话,可以用if-else语句,类似如下:
33.对于需要有一个值作为关键字,然后其后对应多个值,可以设置为map类型,代码如下:
34.如果用while对于某一个值cnt来循环,可以设置为
35.用printf输出string类型字符串
36.c++11新特性,直接输出vector的元素值
37.c++11新特性,将map的关键字和元素值对应到结构数组中:
38.38.关于set类型的用法(默认从小到大排序,重复的不要):

1.isdigit()判断字符是否为数字字符?

是,返回1;否则,返回0

#include<iostream>
using namespace std;
int main()
{
   
    char a;
    cin >> a;
    cout << isdigit(a);
    return 0;
}

2.isalpha()判断字符是否为字母

大写字母,返回1;小写字母,返回2;非字母,返回0

#include<iostream>
using namespace std;
int main()
{
   
    char a;
    cin >> a;
    cout << isalpha(a);
    return 0;
}

3.对字符串,从第i个位置开始,插入k个j

s.insert(i,k,j);
#include<iostream>
#include<string>
using namespace std;
int main()
{
   
    string a;
    cin >> a;
    a.insert(2,3,'b');  //从第2个位置开始,插入3个b
    cout << a;
}

4.根据字符串中的字符,按照降序排列

#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(char a,char b)
{
   
    return a>b;
}
int main()
{
   
    string s;
    cin >> s;
    sort(s.begin(),s.end(),cmp);
    cout << s;

}

5.将字符串转化为数字

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   
    string s;
    cin >> s;
    int a=stoi(s);
    cout << a;
}

注意:
1. 如果字符串中出现非数字,则只将非数字字符前的数字字符转化

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   
    string s;
    cin >> s;
    int a=stoi(s);
    cout << a;
}

在这里插入图片描述
2.如果开头第一个为非数字字符,就有如下报错
在这里插入图片描述

6.将数字转化为字符串

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   
    int a;
    cin >> a;
    string s=to_string(a);
    cout << s;
}

注意:
1. 如果输入时出现非数字,则只将非数字前的数字转化为字符串
在这里插入图片描述
2.如果第一数字为非数字,则输出0
在这里插入图片描述

7.对于vector定义的数组连续竖着for输入需要指明数组长度

#include<iostream>
#include<vector>
using namespace std;

int main()
{
   
    int n;
    cin >> n;
    vector<int> a(n);  //不定以数组长度大小,否则不能连续for输入
    for(int i=0; i<n; i++)
        cin >> a[i];
    return 0;
}

在这里插入图片描述
否则,
在这里插入图片描述

8.s.substr()截取字符串的字符

#include<iostream>
#include
  • 5
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值