2022-04-08----算法库—sort—排序
#include<cstdio>
#include<iostream>
#include<algorithm>//算法库
using namespace std;
int a[10];
int main(){
int i=0;
for(i=0;i<10;i++){
a[i]=i;
}
for(i=0;i<10;i++){
printf("%d",a[i]);
}
sort(a,a+10,greater<int>());
/*
sort ----C++里的排序函数,默认从小到大排序,
sort(首地址,尾地址+1,greater<int>());-----greater 从大到小排,
*/
printf("\n");
for(i=0;i<10;i++){
printf("%d",a[i]);
}
}
2022-4-8 -----容器-----集合set
#include<iostream>
#include<string>
#include<set> //容器---集合
/*
insert ----插入元素
erase-----删除一个元素
count-----统计集合中元素的个数
size-------获取元素个数
clear-------清空(会清空内存)
*/
#include<algorithm>//算法库
using namespace std;
int main(){
set<string> country;
country.insert("China");
country.insert("America");
country.insert("France");
country.insert("China");
set<string>::iterator it;
for(it=country.begin();it!=country.end();it++){
cout<<*it<<endl;
}
country.erase("America");
country.erase("EngLand");
if(country.count("China")){
cout<<"在里面"<<endl;
}else{
cout<<"不在"<<endl;
}
for(it=country.begin();it!=country.end();it++){
cout<<*it<<endl;
}
country.clear();
return 0;
}
2022-4-8-------集合set—
2022-4-9—被字符串+指针搞的一天
string s ;----字符串可以看出一个数组(只出现在c++)
今天又碰到了weer(int &a)——————这种引用,
这种引用只出现在C++中哈
在c中要引用------用指针啊;
明日复习*p+±---- * ++p
蓝桥杯真的无语了