1. 程式人生 > >【程式碼模板】不存在的NOIP2017

【程式碼模板】不存在的NOIP2017

雖然可能沒機會參加NOIP2017的複賽了
但是這份模板我還是會在比賽前完成它的,
作為對我過去一年的反饋。

因為技能樹點歪,,所以我會棄坑重新來點,
辣麼,,模板題的理解就很重要,他直接決定了其他的題目你寫不寫的來。。
所以,這裡的許多東西也許沒辦法在OJ上直接驗證正確性(這也是打模板的痛苦之處)
不過我會盡力去找的,並且也會把自編的資料存放下來。
就醬紫。

frame

//這個專案提供了程式基本的程式碼框架

//標頭檔案模板
#include<iostream>
#include<algorithm>
#include<cstdio>
#include
<cstring>
#include<cctype> #include<iomanip> #include<sstream> #include<cmath> #include<string> #include<vector> #include<stack> #include<queue> #include<map> #include<set> #include<bitset> #include<list> //名稱空間 using namespace
std; //宣告與巨集定義 typedef long long LL; typedef long double LD; #define fst first #define sec second #define mp make_pair //常量定義 const int N = 1e5, inf = 1e9; //代替define的寫法 & e計數法的使用 //輸入輸出優化 int readint(){ //readint好簡單啊為什麼。。。 int x=0, op=1; char ch = getchar(); //一定要賦初始值 while(ch < '0' || ch >
'9'){ if(ch=='-')op=-1; ch = getchar(); } while(ch >= '0' && ch <= '9'){ x=x*10+ch-'0'; ch = getchar(); } return x*op; } int main(){ cout<<"Hello World"<<endl; return 0; }

STL

//這個專案提供了STL的範例
//NOIP前第一輪模板 2017.10.5

//順序容器:vector, deque, list
//關聯容器:set, map,
//適配容器:stack, queue, priority_queue
#include<iostream>
#include<set>  //基於紅黑樹
#include<map>  //基於平衡二叉樹
#include<vector>  //時間換空間(逃
#include<string> //各種黑科技
#include<bitset>

using namespace std;

//操作整理:宣告,插入,刪除,查詢,遍歷
//用法整理:你自己想啊

void setting(){
	set<int>myset; //宣告int型別的集合(突然發現重名好像不會炸233333)
	
	//1. 基本操作
	myset.insert(233);  //往裡面新增元素(重複插入無效)
	myset.erase(233);  //刪除裡面的某個元素(如果不存在該元素則不操作)(這裡也可以用迭代器刪除區間)
	myset.count(233); //查詢集合中是否存在某個元素
	myset.clear();   //清空集合
	
	//2. 迭代器
	myset.insert(233);  myset.insert(322);
	set<int>::iterator it;  //如果重名宣告迭代器的時候會炸掉
	set<int>::reverse_iterator rit; //反向迭代器
	for(it = myset.begin(); it != myset.end(); it++){
		cout<<*it<<" ";
	}
	cout<<"\n";
	for(rit = myset.rbegin(); rit != myset.rend(); rit++){
		cout<<*rit<<" ";
	}
	cout<<"\n";
	
	//3. 熟練搞事
	cout<< (myset.find(233)==myset.begin()) <<" \n"; //查詢鍵值的位置並返回迭代器
	cout<< *myset.lower_bound(234)<<"\n";  //返回第一個>=key的元素的迭代器
	cout<< *myset.upper_bound(233)<<"\n";  //返回第一個>key的元素的迭代器
}

void maping(){ 
	map<int,int>mymap; //左鍵右值
	
	//1. 基本操作,,同為關聯容器,基本和set差不多吧
	mymap[5] = 7;  //新增元素(注意 "mymap[0];" 同樣往map中添加了元素,只是沒有賦值而已)
	
	//2. 迭代器
	map<int,int>::iterator it = mymap.begin();
	cout<<(it->first)<<" "<<(it->second)<<"\n"; //map遍歷時訪問的是pair型別
	
	//3. 
	
}

void bitsetting(){
	
}

void stringing(){
	string str = "123456789";  char ch[110]="233";
	
	//建構函式
	str = string(ch); //用c語言字串s初始化
	str = string(5,'c');  //用5個字元c初始化
	string s1 = str;  //賦值操作
	
	//基本特性
	str.size(); //返回大小
	
	//各種操作
	str.substr(0, 2);  //返回子串,返回0開始的由兩個字元組成的字串
	
	
}

int main(){
	stringing();
	cout<<"Hello World"<<endl;
	return 0;
}