![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++基础
小兔崽崽!
我还年轻!!!
展开
-
松哥的困惑 STL
思路:直接先找字符串中有没有三个大写的字符,三个大写的字符就满足了名字是三个字,然后再用string类中的find方法找子串,如果存在就返回第一个找到的子串的位置,否则返回-1.#include <bits/stdc++.h>using namespace std;int n;int main(){ while(cin>>n){ while(n--){ string s; cin>>s; .原创 2020-11-10 19:05:02 · 163 阅读 · 0 评论 -
C. Yet Another Walking Robot
There is a robot on a coordinate plane. Initially, the robot is located at the point (0,0). Its path is described as a string s of length n consisting of characters ‘L’, ‘R’, ‘U’, ‘D’.Each of these c...原创 2020-02-07 20:33:13 · 193 阅读 · 0 评论 -
购物(优先队列,DP)
思路:这道题可以用DP写也可以用优先队列写,我用的是优先队列,首先就是将每一天的价格sort排序,至于格外要支付k*k的费用只需要将数组处理一下就好,a[i][j] = a[i][j]+2*j+1;然后按天数把当天的所以糖果的价格放入优先队列,再将最先出队的买了,这样就可以保证费用少。#include <bits/stdc++.h>using namespace std;int a[310][310];priority_queue<int,vector<int>,.原创 2020-08-04 14:43:53 · 118 阅读 · 0 评论 -
闪闪发光 (思维,STL)
思路:2^1 2 ^1 两个数加起来可以变成 2 ^2 ,所以只需要遍历一遍,将两个相同的数遍成一个加1的数,最后统计剩下的数就是最少的举重次数。 下面就用两种方法来写这道题。`#include <bits/stdc++.h>using namespace std;int cnt[2000050];int main(){ int n; while(cin>>n){ memset(cnt,0,sizeof(cnt)); i.原创 2020-11-05 19:44:54 · 117 阅读 · 0 评论 -
sort排序详解
sort函数默认的排序方式是升序排序,即从小到大。1.对简单的数组排序简单来说就是sort(begin,end,cmp);sort函数中参数有三个(第三个可以省略)其中begin是排序数组的起始地址end是排序数组的结束地址(最后一位要排序元素的地址)这两个参数都是地址。#include <iostream>#include<algorithm>using...原创 2019-12-08 16:12:13 · 23374 阅读 · 1 评论 -
vector 容器基本用法
1、vector用来创建动态数组对象,其相当于一个容器。vector不是一个类,而是一个类模板。用vector定义动态数组的形式为 :vector<元素类型> 数组对象名(数组长度) //数组长度可有可无。vector<int> v; //创建一维整型数组对象vvector<vector<int>> test ...原创 2019-10-09 20:09:28 · 597 阅读 · 0 评论 -
set容器用法(去重)
关于set,必须说明的是set关联式容器。set作为一个容器也是用来存储同一数据类型的数据类型,并且能从一个数据集合中取出数据,在set中每个元素的值都唯一,而且系统能根据元素的值自动进行排序。应该注意的是set中数元素的值不能直接被改变。set中常用的方法begin() ,返回set容器的第一个元素end() ,返回set容器的最后一个元素clear() ...原创 2019-10-09 20:26:02 · 807 阅读 · 0 评论 -
优先队列C++STL
优先队列的定义优先队列是一种抽象的数据类型,行为有些像队列,但先出的队列元素步数先进队列的元素,而是队列中优先级最高的元素.STL的优先队列也定义在头文件里,用priority_queue<int>pq;来声明。这是一个越小的整数优先级越低的优先队列。优先队列的基本操作q.size();//返回q里元素个数q.empty();//返回q是否为空,空则返回1,否则返回0q.push(k);//在q的末尾插入kq.pop();//删掉q的第一个元素q.top();//返回q的第一个原创 2020-08-04 14:32:04 · 264 阅读 · 0 评论 -
拯救单身狗
直接判断里面的每个元素出现次数是不是偶数就行,如果是奇数就输出NO。#include <bits/stdc++.h>using namespace std;int t, x,flag;int main(){ cin>>t; for(int i=0; i<t; i++) { map<int,int>mp; set<int>s; while(cin>>x&.原创 2020-08-04 14:46:30 · 90 阅读 · 0 评论 -
unique
在STL中unique函数是一个去重函数, unique的功能是去除相邻的重复元素(只保留一个),其实它并不真正把重复的元素删除,是把重复的元素移到后面去了,然后依然保存到了原数组中,然后 返回去重后最后一个元素的地址,因为unique去除的是相邻的重复元素,所以一般用之前都会要排一下序。注意,words的大小并没有改变,依然保存着10个元素;只是这些元素的顺序改变了。调用unique“删除”了...原创 2019-10-09 20:31:57 · 442 阅读 · 0 评论 -
C. Eugene and an array(Round #632 Div 2)前缀和
Eugene likes working with arrays. And today he needs your help in solving one challenging task.An array c is a subarray of an array b if c can be obtained from b by deletion of several (possibly, zer...原创 2020-04-15 01:06:12 · 169 阅读 · 0 评论 -
丑数
丑数是指不能被2,3,5以外的其它素数整除的数,把丑数从小到大排列起来,结果如下:1,3,4,5,6,8,9,10,12,15,…求第1500个丑数。#include<bits/stdc++.h>using namespace std;typedef long long ll;const int coeff[3] = {2,3,5};int main(){ prio...原创 2020-02-12 02:10:52 · 187 阅读 · 0 评论 -
Let the Balloon Rise(map)
Let the Balloon RiseTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 170176 Accepted Submission(s): 67812Problem DescriptionContest time a...原创 2019-11-14 23:32:45 · 125 阅读 · 0 评论 -
组队分配
思路:这道题只需要用到结构体排序。#include <bits/stdc++.h>using namespace std;struct student{ string name; int sore;};int cmp(student st1,student st2){ return st1.sore<st2.sore;}int main(){ int t; cin>>t; while(t--){ student .原创 2020-11-10 19:51:38 · 181 阅读 · 0 评论 -
C语言判断闰年
如果一个年份是闰年要满足一下条件:1、能被4整除,但不能被100整除;2、能被400整除; 所以判断闰年的条件为(year%4==0&&year%100!=0)||year%400==0#include<bits/stdc++.h>using namespace std;int main(){ int year ; cin>>year; if((year%4==0&&year%100!=0)||year%400==原创 2020-07-26 10:41:43 · 578 阅读 · 0 评论 -
【C++】C++中substr的用法
string 类型中substr函数是一个用于构造字符串的函数格式为:s.substr(pos, n)其中pos是启示位置,n是构造之后字符串的长度所以我们可以用这个函数来构造出一个字符串的子串。#include <iostream>using namespace std;int main(){ string s = "hello world!!!"; string x = s.substr(6,8); cout<<x<<endl;原创 2020-07-22 09:39:57 · 365 阅读 · 0 评论 -
C++中count函数用法
count函数可以用来统计字符串中某个字符的个数使用方法是count(begin,end,‘a’),其中begin指的是起始地址,end指的是结束地址,第三个参数指的是需要查找的字符。#include <bits/stdc++.h>using namespace std;int main(){ string s= "abcdefgaabbccd"; int num =count(s.begin(),s.end(),'a'); cout<<num&l原创 2020-07-21 10:58:09 · 30656 阅读 · 1 评论 -
c++知识点总结
封装:就是将类的成员按使用或存取的方式分类,从而有条件的限制对类的成员的使用。构造函数:在定义对象的同时被调用。构造函数没有返回值类型,前面不能加void。构造函数可以重载。构造函数的函数名必须和类名相同。析构函数:没有返回值的函数,不能随意调用,也没有重载,一个类中只能由一个析构函数。拷贝构造函数:类名::类名(const 类名 & 对象名)也是一种构造函数,所以其函...原创 2019-12-22 23:11:52 · 86 阅读 · 0 评论 -
this指针
#include <iostream>using namespace std;class POINT{private: double x,y;public: void set1(double a,double b) { x=a; y=b; } void show() { cout...原创 2019-09-26 19:42:57 · 122 阅读 · 0 评论 -
位运算 异或^
异或运算原理:两个二进制数字,对同位置的数字进行比较,“相同为0,相异为1”。原创 2019-09-21 10:17:00 · 66 阅读 · 1 评论 -
构造函数析构函数
定义:所谓构造函数就是在对象创建时其作用的一个特殊成员函数,因此通常使用构造函数来实现类中数据的初始化,构造函数从形式上看就是一个函数,但是规定它必须与类的名字一直,病区没有返回类型。而析构函数是构造函数的补充。析构函数是在对象被销毁之前起作用的特殊成员函数,通常用于做一些收尾工作。析构函数看起来也与一般成员函数一样,但是它的函数名必须是所属类名前面加一个~,并且同样不允许有返回值#incl...原创 2019-08-22 16:52:44 · 111 阅读 · 0 评论