stoi(string)接收string字符串,转换成int(32 位有符号整型)取值上限:\(2^{31}-1\),超出会报错溢出。stoll(string)接收string字符串,转换成long long(64 位有符号整型)取值范围极大,本题运算推荐用它,防止中间计算溢出
#include <cctype>是 C++ 标准库中:
🌟 字符处理库
专门用于:字符判断、字符转换的头文件。
一、字符类型判断函数
二、字符转换函数
tolower tolower('A') → 'a' ‘A’+32
toupper toupper('a') → 'A'
三、字符串处理函数
比较 s1.compare(s2) 返回两个字符编码的差值
分割字符串:
C++ 没有官方 split。通常:stringstream
string s = "a,b,c"; stringstream ss(s); string temp; while(getline(ss, temp, ',')) { cout << temp << endl; }