c++
文章平均质量分 56
RyannchenOO
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
cpp 字符 字符串 字符数组处理
字符数组使用 getline与'\0' #include<iostream> using namespace std; /* 输入可能带空格的字符串,计算并输入其长度(即字符个数,含空格数)。 字符串最大长度不超过100。 使用字符数组实现,不使用字符串库函数。 */ int charlen(char str[]) { //计算字符串长度 int len = 0; while (str[len] != '\0') { len++; } return len; } int ma原创 2022-03-12 16:32:22 · 3273 阅读 · 1 评论 -
cpp-位运算
1、消去整数x从右→左的第一个1(最后一位1) 原理: x+"全1"→让最后一位1右边的0全变为1,最后一位1由于进位变成0,最后一位左边的所有位由于其进1而全1都+1进位变成+0座椅保持不变 令x+"全1"→y 则y与x只有从右边到最后一位正好相反。故进行与正好可以使得这些不同的位都变成0==>消去了最后一位1 -----应用1:用O(1)时间检测整数n是否是2的幂次. 2的幂次:消去最后一位1后应该均为0 0001 0010 0100 1000 #include<原创 2022-03-08 20:35:39 · 908 阅读 · 0 评论 -
算法:二分法
有时候迭代法更方便 #include <iostream> #include<cmath> #include <limits.h> using namespace std; //求方程2x^3−4x^2+3x−6=0 double func(double x){ double res = 2*x*x*x - 4*x*x + 3*x - 6; return res; } //用迭代法二分能求,用递归法失败!有时候要灵活选择 int main(){ d.原创 2022-03-07 17:33:30 · 202 阅读 · 0 评论 -
leetcode-二分查找
704.Binary Search (1) Binary Search - LeetCode 迭代方式 int search(vector<int>& nums, int target) { int lo = 0; int hi = nums.size()-1; while(lo<=hi){ int mid = (lo+hi)/2; if(nums[mid] .原创 2022-02-07 12:29:19 · 963 阅读 · 1 评论 -
C++ 标准输入、输出流
1、流的概念 C++ 的 I/O 发生在流中,流是字节序列 输入流:从设备流向内存的字节流 输出流:从内存流向设备的字节流 标准输入流:从标准输入设备(键盘)流向内存的数据源 >> 不接收空格、回车,以空格、回车做分隔符 ...原创 2022-01-18 13:12:43 · 1643 阅读 · 0 评论
分享