随笔分类 - C++ tips
摘要:int oneNumInBinary(int n){ int cnt=0; while(n){ n = n&(n-1); cnt++; } return cnt; }
阅读全文
摘要:#include "stdafx.h" #include #include #include #include #include #include using namespace std; //sstream string int2str1(int n){ ostringstream oss; oss > n; return n; } //sscanf int s...
阅读全文
摘要:transform函数在anlgorithm里,四个参数分别为,①被转换字符串头、②被转换字符串尾、③用来存放转换后的字符串头、④转换类型 在转换大写的例子中,如果没有resize会报错,因为需要事先确定用来存放转换后字符串的大小足够装得下。 参考:http://www.ijophy.com/201
阅读全文
摘要:利用algorithm库里的max_element和min_element可以得到vector的最大最小值,配合distance函数可以得到最大值的位置 输出结果: 9 6 1 0 当vector中有多个最小最大值时,位置取的是第一个
阅读全文

浙公网安备 33010602011771号