福建工程建设网站,广州建网站有哪些,网站开发的技术内容,程序开源网站for(char c:s)遍历字符串 增强型for循环 C for(char c:s)遍历字符串 增强型for循环_c for (char c : s)-CSDN博客 字符串使用前要进行扩容 reserve函数 【CString类成员函数辨析】resize(),size(),capacity(),reserve()函数的解析与对比_c reserve函数-CSDN博客 a.size() 用来…for(char c:s)遍历字符串 增强型for循环 C for(char c:s)遍历字符串 增强型for循环_c for (char c : s)-CSDN博客 字符串使用前要进行扩容 reserve函数 【CString类成员函数辨析】resize(),size(),capacity(),reserve()函数的解析与对比_c reserve函数-CSDN博客 a.size() 用来计算字符串的长度末尾的\0不计算在内 交替合并字符串
class Solution {
public:string mergeAlternately(string word1, string word2) {int mword1.size();int n word2.size();string ans;int i0;int j0;ans.reserve(mn);while(im||jn){if(im){ans.push_back(word1[i]);i;}if(jn){ans.push_back(word2[j]);j;}}return ans;}
};
找不同
class Solution {
public:char findTheDifference(string s, string t) {/*for(int i0;is.size();i)t[0]^s[i];for(int i1;it.size();i)t[0]^t[i];return t[0];}*/vectorint cnt(26,0);//创建1个容量为26的动态数组初始值为0for(char ch:s) //遍历string每一个元素{cnt[ch-a];//s中存在的字母 对应的cnt值为1}for(char ch:t){cnt[ch-a]--;//t中存在且s中没有存在的字母 对应的cnt值为-1if(cnt[ch-a]0){ return ch;//该元素为s,t中不同的元素}}return ;}
}; 异或运算的特性 异或自己得0任何数异或0得自己本身 具有交换律、结合律例如 1^2^3^4^2^3^1 (1^1)^(2^2)^(3^3)^4 0^0^0^4 0^4 4; 总结异或运算擅长找不同。 遍历两个字符串时间复杂度O(mn) #include iostream
#include string
using namespace std; int main() { string date; cin date; // 假设输入的日期格式是 yyyy-mm-dd我们需要提取出月份和日期 int month stoi(date.substr(5, 2)); // 提取月份从索引5开始长度为2 int day stoi(date.substr(8, 2)); // 提取日期从索引8开始长度为2 // 判断逻辑如果月份小于10或者月份等于10且日期小于等于29则还可以训练 if (month 10 || (month 10 day 29)) { cout No. Its not too late.; } else { cout QAQ; } return 0;
}
stoi函数作用是将 n 进制的字符串转化为十进制使用时包含头文件string C常用函数--stoi函数用法总结-CSDN博客date. date.substr(a,b) //从第a位开始一共b个
substr函数的使用-CSDN博客