
C++
学习不易
直到有一天,可以和你并肩站立
展开
-
C++使用count函数统计string里面出现的字符的个数
代码实现 for(auto v:J)时C++11中新特性,类似于java中的for each #include<iostream> #include<vector> using namespace std; int Agm(string J, string S) { int cnt = 0; for (auto v : J) { cnt += count(S.begin(), S.end(), v); } return cnt; } int main() { stri原创 2020-07-23 22:40:38 · 5265 阅读 · 2 评论 -
C++ 位运算 判断两数是否相等
代码实现 int a = 1; int b = 2; if (!(a ^ b)) { cout << "两数相等"; } else { cout << "两数不等"; } 两数不等原创 2020-07-22 22:41:59 · 4397 阅读 · 1 评论 -
C++中Iterator的find方法查询vector数组中元素
相关解释 i = find(v.begin(), v.end(), 1);find方法从v.begin()~v.end()中找1 这个元素。如果i==v.end,就代表着迭代器i遍历了v动态数组都没有找到,所以输出No,找到了就代表这遍历得位置。 i-v.begin()表示找到的位置索引。 /* */中相关数据,第一行为find里查找的元素,第二行为三个输出 代码 #include<io...原创 2020-04-28 19:56:05 · 6220 阅读 · 0 评论