c++
基本框架
#include<bits/stdc++.h>
using namespace std;
int main(){
return 0;
}
栈
函数
#include<bits/stdc++.h>
using namespace std;
int main(){
//void
push()//入栈
pop()//删除栈顶元素
//int
size()//栈的长度
//bool
empty()//栈是否为空
//
top()//获取栈顶元素
return 0;
数组模拟栈
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int Stack[N];
int top=-1;
void push(int n){//入栈
if(top>=N){
cout << "[Error]栈满了\n";
return ;
}
Stack[++top]=n;
}
int gettop(){//获取栈顶元素
if(top<0){
cout << "[Error]栈空\n";
}
return Stack[top];
}
void pop(){//删除栈顶元素
if(top<0){
cout << "[Error]栈空\n";
return ;
}
top--;
}
int size(){//返回栈的长度
return top+1;
}
bool empty(){//栈是否为空
return size()==0;
}
void clear(){//清空栈
top = -1;
}
int main(){
return 0;
}
数组模拟队列
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int Queue[N];
int topt=0,topw=-1;
int size(){//返回队列的长度
return topw-topt+1;
}
bool empty(){//队列是否为空
return size()==0;
}
void push(int n){//入队
if(topw==N){
cout << "[Error]队列满了\n";
return ;
}
Queue[++topw]=n;
}
int getfront(){//获取队头元素
if(empty()){
cout << "[Error]队列空\n";
}
return Queue[topt];
}
int getback(){//获取队尾元素
if(empty()){
cout << "[Error]队列空\n";
}
return Queue[topw];
}
void pop(){//出队元素
if(empty()){
cout << "[Error]队列空\n";
return ;
}
topt++;
}
void clear(){//清空队列
topt = 0;
topw = -1;
}
int main(){
return 0;
}
读、写入文件
#include<bits/stdc++.h>
using namespace std;
int main(){
//写入
freopen("/*文件名加后缀*/","w",stdout);
cout << "/*写入的内容*/";
fclose(stdout);//停止写入
return 0;
}
常用函数
#include<bits/stdc++.h>
using namespace std;
int main(){
abs();//绝对值
return 0;
}
deBUG
#include<bits/stdc++.h>
#define deBUG(var) cout << "[deBUG]" << #var << "=" << var << endl;
using namespace std;
int main(){
int n;
cin >> n;
deBUG(n);
return 0;
}
三目运算符
#include<bits/stdc++.h>
using namespace std;
int main(){
/*式子*/ ? /*结果为真(不为0)执行(返回)这个式子*/ : /*结果为假(为0)执行(返回)这个式子*/;
return 0;
}
排序
字符串内部排序(降序,不写cmp是升序)
#include<bits/stdc++.h>
using namespace std;
bool cmp(char x,char y){
return x>y;
}
int main(){
string s;
cin >> s;
sort(s.begin(),s.end(),cmp);
cout << s;
return 0;
}