第一次打卡哦:C++基础
模版代码:
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
priority_queue<int, vector<int>, greater<int> >q;
struct node{
int a, b;
int operator + (const node &t) const
{return b+t.a;}
}x, y;
bool cmp(const int&, const int&);
void qsort(int, int);
int q1[8] = {9,1,2,0,8,19,99,80};
int q2[10] = {0,9,1,2,0,8,19,99,80};
int q3[8] = {9,1,2,0,8,19,99,80};
int main()
{
x = {1, 2}, y = {9, 8};
//STL快排
sort(q1, q1+8, cmp);
for(int i=0; i<8; ++i)
printf("%d ", q1[i]);
printf("\n");
//手写快排
qsort(1, 8);
for(int i=1; i<=8; ++i)
printf("%d ", q2[i]);
printf("\n");
//重载运算符
int t = x+y;
printf("%d\n", t);
//优先队列
for(int i=0; i<8; ++i)
{
int tmp = q3[i];
q.push(tmp);
}
while(q.size() > 0)
{
printf("%d ", q.top());
q.pop();
}
return 0;
}
bool cmp(const int &a, const int &b)
{
return a<b;
}
void qsort(int left, int right)
{
if(left > right)
return;
int tmp;
tmp = q2[left];
int i=left, j=right;
while(i != j)
{
while(q2[j]>=tmp && i<j)
--j;
while(q2[i]<=tmp && i<j)
++i;
if(i < j)
swap(q2[i], q2[j]);
}
q2[left] = q2[i];
q2[i] = tmp;
qsort(left, i-1);
qsort(i+1, right);
return;
}
emmm,结构体赋值用的C++11语法,懒一下哈~
巨佬模版
/*
作者:路讯先生
类型:模板
博客链接:https://lxxs.xyz/
*/
#include<bits/stdc++.h>
#define N 10000010
#define For(i,l,r) for(int i = l;i<=r;i++)
#define INF 0x3f3f3f3f
#define PII pair<int,int>
#define LL long long
#define ULL unsigned long long
#define mod 1e9+7
#define it ::iterator
using namespace std;
struct node{
int a,b;
node operator +(const node f)const{
node tmp;
tmp.a=a+f.a;
tmp.b=b+f.b;
return tmp;
}
};
int main(){
queue<int> a;
a.pop();a.push();a.size();a.empty();a.back();a.front();
priocity_queue<int,vector<int>,greater<int> >b;
b.push();b.top();b.top();
string s;
s.size();s.length();s.clear();s.substr();
PII c;
c.first;c.second;
stack<int> d;
d.push();d.pop();d.top();d.empty();d.size();
map<int,int>e;
e.insert({,});e.erase();e.find;e[];
int f=(LL)f*mod%mod;
freopen("x.in","r",stdin);
freopen("x.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
memset(ss,0x3f,sizeof ss);
vector<int> q;
for(vector<int>it i=q.begin();i!=q.end();i++)
l = lower_bound(all+1,all+allsi+1,que[i].fir)-all;
allsi=unique(all+1,all+allsi+1)-(all+1);//去重并获取最后一个数的下标
swap(a,b);
sort(a+1,a+n+1);
reverse(a+1,a+n+1);
next_permutation(a+1,a+n+1);
prev_permutation(a+1,a+n+1);
}
新增:栈与队列STL
栈
#include<cstdio>
#include<algorithm>
#include<stack>
#include<iostream>
using namespace std;
stack<char>s;
void sta();
void que();
int main()
{
sta();
return 0;
}
void sta()
{
char t;
int n;
scanf("%d", &n);
for(int i=1; i<=n; ++i)
{
cin >> t;
if(t == '(')
s.push(t);
if(t == ')')
if(!s.empty())
s.pop();
else
{
printf("No\n");
return;
}
}
if(!s.empty())
printf("No\n");
else
printf("Yes\n");
return;
}
队列
#include<cstdio>
#include<queue>
using namespace std;
queue<int>m;
queue<int>w;
int main()
{
int flag = 0, x, y;
int male, female, number;
scanf("%d%d%d", &male, &female, &number);
while(flag != male)
m.push(++flag);
flag = 0;
while(flag != female)
w.push(++flag);
for(int i=0; i<number; ++i)
{
printf("%d %d\n", m.front(), w.front());
x = m.front();
y = w.front();
m.pop();
w.pop();
m.push(x);
w.push(y);
}
return 0;
}