
STL
C++程序标准库
繁星蓝雨
Happy coding!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
283. 移动零——附带详细代码和思路
文章目录1 题目2 思路3 代码1 题目2 思路思路1:如果遇到0,就是删除,然后再末尾再加上0。⚠️注意点:如果删除元素后,会使得删除元素后的迭代器失效,删除元素后,会返回删除后的那个迭代器。思路2:所有非零元素都向前覆盖前面的元素,把没有覆盖后的元素全部赋值为0.3 代码class Solution {public: void moveZeroes(vector<int>& nums) { int len = nums.size(原创 2022-03-19 20:00:00 · 257 阅读 · 0 评论 -
912. Sort an Array(排序数组)———附带思路和完整代码
文章目录0 效果1 题目2 思路3 代码0 效果1 题目2 思路排序的API调用3 代码C++:class Solution {public: vector<int> sortArray(vector<int>& nums) { auto cmp = [](int a, int b)->bool { return a < b; }; std::sort(nums.b原创 2021-12-14 17:28:11 · 1001 阅读 · 0 评论 -
剑指 Offer 58 - II. 左旋转字符串
文章目录0 效果1 题目2 思路3 代码0 效果1 题目2 思路考察指针和string操作,有些小细节容易出错。注意:1,char数组最后一个字符需要是\0;2,string字符串按位赋值为初始化时,不能使用 s2[i]=s1[i] 进行赋值;要使用这样的语句:s2=s2+s1[i]。3 代码法1:char* reverseLeftWords(char* s, int n){ int length = 0; for(;*(s + length) != '\0';le原创 2021-12-13 20:29:53 · 421 阅读 · 0 评论 -
1108. IP 地址无效化
文章目录0 效果1 题目2 思路3 代码0 效果1 题目2 思路考察string和char数组的操作。3 代码C++:class Solution {public: string defangIPaddr(string address) { auto replace_all= [](string& str, const string& old_s, const string& new_s){ for(string ::原创 2021-12-13 20:32:06 · 1549 阅读 · 0 评论 -
1470. Shuffle the Array(数据重排列)
文章目录0 效果1 题目2 思路3 代码0 效果1 题目2 思路简单的数组或向量操作。3 代码C++:class Solution {public: vector<int> shuffle(vector<int>& nums, int n) { vector<int> c; for (int i = 0; i < n; ++i) { c.push_back(nums[i]);原创 2021-12-13 20:16:04 · 220 阅读 · 0 评论 -
稀疏向量(202006-2/CCF)————附思路和完整代码
文章目录0 效果1 题目2 思路2.1 优化:3 代码0 效果使用unordered_map(未排序key的散列map,速度比map快很多)【实际运行的速度比map满????,这个就不知道编译怎么执行的了,可能是使用namespace导致的】使用map难点:性能优化,尽量减少时间和空间复杂度。1 题目2 思路存储两个两个稀疏向量,如果两个稀疏向量相同的index上都有value(不为0),那么就用两个值相乘,计算所有这样乘积的和。2.1 优化:1 使用vector来优化存储第一个原创 2020-10-05 11:37:33 · 365 阅读 · 0 评论 -
乒乓球筐————hash映射(可用map)
文章目录1 题目2 解析2.1 题意2.2 思路3 参考代码3.1 用map3.2 不用map1 题目乒乓球筐时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小)题目描述nowcoder有两盒(A、B)乒乓球,有红双喜的、有亚力亚的……现在他需要判别A盒是否包含了B盒中所有的种类,并且每种球的数量不少于B盒中的数量...原创 2020-03-01 18:30:18 · 444 阅读 · 0 评论 -
第七届蓝桥杯C++B组:最大比例
X星球的某个大奖赛设了M级奖励。每个级别的奖金是一个正整数。并且,相邻的两个级别间的比例是个固定值。也就是说:所有级别的奖金数构成了一个等比数列。比如:16,24,36,54其等比值为:3/2现在,我们随机调查了一些获奖者的奖金数。请你据此推算可能的最大的等比值。输入格式:第一行为数字 N (0<N<100),表示接下的一行包含N个正整数第二行N个正整数Xi...原创 2019-03-16 16:26:23 · 588 阅读 · 0 评论 -
第四届蓝桥杯C++B组 标题:错误票据
某涉密单位下发了某种票据,并要在年终全部收回。 每张票据有唯一的ID号。全年所有票据的ID号是连续的,但ID的开始数码是随机选定的。 因为工作人员疏忽,在录入ID号的时候发生了一处错误,造成了某个ID断号,另外一个ID重号。 你的任务是通过编程,找出断号的ID和重号的ID。 假设断号不可能发生在最大和最小号。要求程序首先输入一个整数N(N&...原创 2019-03-04 08:09:32 · 604 阅读 · 1 评论 -
第九届蓝桥杯C++B组:递增三元组
给定三个整数数组A = [A1, A2, ... AN],B = [B1, B2, ... BN],C = [C1, C2, ... CN],请你统计有多少个三元组(i, j, k) 满足:1. 1 <= i, j, k <= N 2. Ai < Bj < Ck 【输入格式】第一行包含一个整数N。第二行包含N个整数A1, A2, .....原创 2019-03-17 17:01:28 · 658 阅读 · 0 评论 -
第九届蓝桥杯C++B组:日志统计
小明维护着一个程序员论坛。现在他收集了一份"点赞"日志,日志共有N行。其中每一行的格式是:ts id 表示在ts时刻编号id的帖子收到一个"赞"。 现在小明想统计有哪些帖子曾经是"热帖"。如果一个帖子曾在任意一个长度为D的时间段内收到不少于K个赞,小明就认为这个帖子曾是"热帖"。 具体来说,如果存在某个时刻T满足该帖在[T, T+D)这段时间内(注意是左闭右开区间)收到不少于...原创 2019-03-17 17:05:13 · 485 阅读 · 0 评论 -
LUCKY STRING————set应用、斐波那契数
文章目录1 题目2 解析2.1 题意2.2 思路3 参考代码1 题目LUCKY STRING时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小)题目描述A string s is LUCKY if and only if the number of different characters in s is a fi...原创 2020-03-02 22:09:23 · 772 阅读 · 0 评论 -
1047 Student List for Course (25分)
文章目录1 题目2 解析2.1 题意2.2 思路2.2.1 思路一2.2.2 思路二3 参考代码3.1 思路一(用vector<\string>)3.2 思路二(char二维数组)1 题目1047 Student List for Course (25分)Zhejiang University has 40,000 students and provides 2,500 co...原创 2020-02-27 10:28:43 · 271 阅读 · 0 评论 -
1039 Course List for Student (25分)
文章目录1 题目2 解析2.1 题意2.2 思路3 参考代码1 题目1039 Course List for Student (25分)Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are s...原创 2020-02-27 09:45:08 · 309 阅读 · 0 评论 -
1063 Set Similarity (25分)
文章目录1 题目2 解析2.1 题意2.2 思路3 参考代码1 题目1063 Set Similarity (25分)Given two sets of integers, the similarity of the sets is defined to be Nc /Nt ×100%, where Nc is the number of distinct common n...原创 2020-02-27 12:17:12 · 314 阅读 · 0 评论 -
1060 Are They Equal (25分)
文章目录1 题目2 解析2.1 题意2.2 思路3 参考代码1 题目1060 Are They Equal (25分)If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0....原创 2020-02-27 16:08:02 · 269 阅读 · 0 评论 -
1022 Digital Library (30分)
文章目录1 题目2 解析2.1 题意2.2 思路3 参考代码1 题目1022 Digital Library (30分)A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and p...原创 2020-02-28 00:06:58 · 274 阅读 · 0 评论 -
1071 Speech Patterns (25分)
文章目录1 题目2 解析2.1 题意2.2 思路3 参考代码1 题目1071 Speech Patterns (25分)People often have a preference among synonyms of the same word. For example, some may prefer “the police”, while others may prefer “the ...原创 2020-02-27 22:38:44 · 323 阅读 · 0 评论 -
1054 The Dominant Color (20分)
文章目录1 题目2 解析2.1 题意2.2 思路2.2.1 思路一(map数组)2.2.2 思路二(不用map数组)3 参考代码3.1思路一3.2 思路二1 题目1054 The Dominant Color (20分)Behind the scenes in the computer’s memory, color is always talked about as a series o...原创 2020-02-27 20:28:48 · 295 阅读 · 0 评论 -
1100 Mars Numbers (20分)
文章目录1 题目2 解析2.1 题意2.2 思路3 参考代码1 题目1100 Mars Numbers (20分)People on Mars count their numbers with base 13:Zero on Earth is called “tret” on Mars.The numbers 1 to 12 on Earth is called “jan, feb, ...原创 2020-02-27 18:56:19 · 330 阅读 · 0 评论