C++ Strings(字符串)

Constructors 构造函数,用于字符串初始化
Operators 操作符,用于字符串比较和赋值
append() 在字符串的末尾添加文本
assign() 为字符串赋新值
at() 按给定索引值返回字符
begin() 返回一个迭代器,指向第一个字符
c_str() 将字符串以C字符数组的形式返回
capacity() 返回重新分配空间前的字符容量
compare() 比较两个字符串
copy() 将内容复制为一个字符数组
data() 返回内容的字符数组形式
empty() 如果字符串为空,返回真
end() 返回一个迭代器,指向字符串的末尾。(最后一个字符的下一个位置)
erase() 删除字符
find() 在字符串中查找字符
find_first_of() 查找第一个与value中的某值相等的字符
find_first_not_of() 查找第一个与value中的所有值都不相等的字符
find_last_of() 查找最后一个与value中的某值相等的字符
find_last_not_of() 查找最后一个与value中的所有值都不相等的字符
get_allocator() 返回配置器
insert() 插入字符
length() 返回字符串的长度
max_size() 返回字符的最大可能个数
rbegin() 返回一个逆向迭代器,指向最后一个字符
rend() 返回一个逆向迭代器,指向第一个元素的前一个位置
replace() 替换字符
reserve() 保留一定容量以容纳字符串(设置capacity值)
resize() 重新设置字符串的大小
rfind() 查找最后一个与value相等的字符(逆向查找)
size() 返回字符串中字符的数量
substr() 返回某个子字符串
swap() 交换两个字符串的内容
时间: 2024-08-24 00:35:21

C++ Strings(字符串)的相关文章

LeetCode OJ:Multiply Strings (字符串乘法)

Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. 给出两个字符串,返回对应数字想乘后的字符串,由于这个字符串可能很大,所以不能采用一般的乘法,这里用的方法是模拟手工的乘法运算,算法 本身很简单,就是当时写的时候有些很小的细节搞错了,找了

[LeetCode] Multiply Strings 字符串相乘

Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. 这道题让我们求两个字符串数字的相乘,输入的两个数和返回的数都是以字符串格式储存的,这样做的原因可能是这样可以计算超大数相乘,可以不受int或long的数值范围的约束,那么我们该如何来计算

Multiply Strings(字符串乘法模拟,包含了加法模拟)

Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. 要求:字符串表示的数字可能无穷大,并且非负. class Solution { private: vector<string> tempStrs; public: string add

[LeetCode] Add Strings 字符串相加

Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. Note: The length of both num1 and num2 is < 5100. Both num1 and num2 contains only digits 0-9. Both num1 and num2 does not contain any leading zero.

UVA 10298 Power Strings 字符串的幂(KMP,最小循环节)

题意:定义a为一个字符串,a*a表示两个字符相连,即 an+1=a*an ,也就是出现循环了.给定一个字符串,若将其表示成an,问n最大为多少? 思路:如果完全不循环,顶多就是类似于abc1这样咯,即n=1.但是如果循环出现了,比如abab,那就可以表示成(ab)2.还有一点,就是要使得n尽量大,那么当出现abababab时,应该要这么表示(ab)4,而不是(abab)2. 此题用神奇的KMP解决,也就是主要利用next数组.举例说明. 一般出现循环的都会大概是这样的:abcabcabc.而这样

43. Multiply Strings 字符串表示的大数乘法

Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. string multiply(string& num, char ch){ int n = ch - '0'; string s; int carry = 0; int x; for(

Codeforces Round #313 (Div. 2) D.Equivalent Strings (字符串)

感觉题意不太好懂 = =# 给两个字符串 问是否等价等价的定义(满足其中一个条件):1.两个字符串相等 2.字符串均分成两个子串,子串分别等价 因为超时加了ok函数剪枝,93ms过的. #include <iostream> #include <cstring> #define clr(x,c) memset(x,c,sizeof(x)) using namespace std; const int N = 200005; char s[N], t[N]; int sc[30],

PHP-redis命令之 strings (字符串)

一.string (字符串) 1.set:设置键 $reids->set('mykey',111); 2.get:获取键 $redis->get('mykey'); 3.del:删除键 $redis->del('mykey'); 4.append:追加 $redis->append('mykey','222'); 5.exists:检查键是否存在 $reids->exists('mykey'); 6.incr/incrby,decr/decrby: 对键加减(键不存在默认为0

43. Multiply Strings 字符串相乘

Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2. Note: The length of both num1 and num2 is < 110. Both num1 and num2 contains only digits 0-9. Both num1 and num2 does not contain any leading z