我這節課都學了啥

HaneDaniko發表於2024-07-31
#include<bits/stdc++.h>
using namespace std;
int main(){
	//#1
	vector<int>a(5);
	fill(a.begin(),a.end(),3);
	for(int i:a)cout<<i<<" ";cout<<endl;
	//#2
	auto func=[&](double x){
		return x*x;
	};
	cout<<func(3)<<endl;
	//#3
	sort(a.begin(),a.end(),[&](int x,int y){return x>y;});
	//#4
	cout<<[=](int x){return x+1;}(3)<<endl;
	//#5
	cout<<a.capacity()<<endl;
	a.clear();cout<<a.capacity()<<endl;
	a.shrink_to_fit();cout<<a.capacity()<<endl;
	//#6
	auto x=minmax({1,3,2,4,5,4,8,5,4,5});
	cout<<x.first<<" "<<x.second<<endl;
	a={1,2,3,2,4,4,3,5,5};
	auto xp=minmax_element(a.begin(),a.end());
	cout<<*xp.first<<" "<<*xp.second<<endl;
	//#7
	vector<int>b(10);
	iota(b.begin(),b.end(),1);
	for(int i:b)cout<<i<<" ";cout<<endl;
	//#8
	auto ii=b.begin();
	auto ij=next(ii);
	cout<<*ij<<endl;
	//#9
	function<int(int,int)>f[4]={
		[&](int x,int y){return x+y;},
		[&](int x,int y){return x-y;},
		[&](int x,int y){return x*y;},
		[&](int x,int y){return x/y;},
	};
	cout<<f[0](1,2)<<endl;
	//#10
	cout<<hypot(1,4)<<endl;//return sqrt{x^2+y^2}
} 

相關文章