10 2023 档案

摘要:在原来的string操作中,大多数都是复制string进行操作,如:substr()、string&传参。它们都会复制占用额外内存。 使用std::string_view犹如只是对它的视图映射进行处理,有一个指针指向一个起始位置,然后会有一个size参数去决定这个指针的移动步数。 #if 1 Pri 阅读全文
posted @ 2023-10-30 19:34 iu本u 阅读(45) 评论(0) 推荐(0) 编辑
摘要:回溯模板: for(start状态:选择列表){ path.push_back(选择); BackTrack(遍历层数); path.pop_back(); } 避免深度方向的重复选择:每次遍历时候层数+1,且start=这时层数 避免广度方向的重复选择:那么start状态应该等于层数 想下一层选择 阅读全文
posted @ 2023-10-30 16:25 iu本u 阅读(4) 评论(0) 推荐(0) 编辑
摘要:它可以将可能存在或者不存在的内容以合适的方式返回,当返回的是空文件时,可以使用_.value_or("初始值") std::optional<std::string> data=OpenFileAsstring("data.txt"); string value=data.value_or("Not 阅读全文
posted @ 2023-10-23 18:58 iu本u 阅读(5) 评论(0) 推荐(0) 编辑
摘要:当返回多个参数时,可以使用tuple、pair,它们都是使用get<0...n>(name)取值 结构体绑定;就是将返回的参数自定义名字,要用"[]"括起来。 std::pair<std::string, int>CreatePerson(){ return { "Kxin",22 }; } aut 阅读全文
posted @ 2023-10-23 16:53 iu本u 阅读(6) 评论(0) 推荐(0) 编辑
摘要:本题有两种思路: 在s中找到t的开头字母,假设s[1]==t[0],那么dp(s,1,t,0)就等于dp(s,2,t,1); 假设在s中找到s[i]==t[j],那么将会有两种情况:1.就让i位置和j匹配:dp(s,i+1,t,j+1)2.不让i位置和j匹配:dp(s,i+1,t,j); 如果i和j 阅读全文
posted @ 2023-10-23 13:08 iu本u 阅读(5) 评论(0) 推荐(0) 编辑
摘要:纸牌问题的解决办法: int piles=0; for(int i=0;i<nums.size();i++){ int poker=nums[i]; int left=0;int right=piles; while(left<right){ int mid=(left+right)/2; if(t 阅读全文
posted @ 2023-10-19 12:59 iu本u 阅读(7) 评论(0) 推荐(0) 编辑
摘要:class Timer { private: std::chrono::time_point<std::chrono::high_resolution_clock>m_StartTimepoint; public: Timer() { m_StartTimepoint = std::chrono:: 阅读全文
posted @ 2023-10-18 21:03 iu本u 阅读(20) 评论(0) 推荐(0) 编辑
摘要:都在运行时执行,而不是在编译时执行,所以有运行成本。它们实际是函数,所以需要传参数,还有返回值。 \static_cast: c++中传统的类型转换直接使用(类型),如果出错也不会提醒错误,但使用static_cast<类型>就会提示 reinterpret_cast: 类型相关的转换,起始是底层内 阅读全文
posted @ 2023-10-16 20:54 iu本u 阅读(23) 评论(0) 推荐(0) 编辑
摘要:右击断点-》选择Conditions/Actions-》增加触发条件(使用{}符号括起要在console上打印的变量) 这样有助于节省时间,可以在运行程序的同时不中断调试代码。 阅读全文
posted @ 2023-10-10 20:54 iu本u 阅读(9) 评论(0) 推荐(0) 编辑
摘要:一般标记了virtual的关键字就是虚函数,虚函数就代表这个函数之后要进行重写; 虚函数增加virtual之后是将会将子类的函数扩展添加进去,而不是重写。 class Base { public: Base() { std::cout << " Base Constructor \n"; } vir 阅读全文
posted @ 2023-10-08 20:03 iu本u 阅读(15) 评论(0) 推荐(0) 编辑
摘要:联合体只有一个成员,所以可以在一个联合体用不同的方式定义一个成员 这一个成员站得内存都是一个内存 联合体可以是匿名的也可以是有名字的 struct Vector2{ float x, y; }; struct Vector4 { union { struct { float x, y, z, w; 阅读全文
posted @ 2023-10-08 19:14 iu本u 阅读(8) 评论(0) 推荐(0) 编辑
摘要:std::sort(vector.begin(),vector.end(),[](int a,int b){ if(a==1)return false;//a为1就将这个1排在最后,因为返回的是false if(b==1)return true;//还是将1排在最后 return a>b;//降序排 阅读全文
posted @ 2023-10-07 13:56 iu本u 阅读(92) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示