helloworld2019

vector非结构体,const不要忘了

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
bool cmp(const int &x,const int &y){
    return x>y;
}
int main()
{
    vector<int> s;
    int tmp;
    for(int i=0;i<4;i++){
        cin>>tmp;
        s.push_back(tmp);
    }
    sort(s.begin(),s.end(),cmp);
    vector<int>::iterator it;
    for(it=s.begin();it!=s.end();it++) cout<<*it<<" ";
}
View Code

vector结构体基本操作

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct node{
    int x;
    int y;
};
    bool gcd (const node &a,const node &b) {
    return a.x>b.x;
    }
int main()
{
    node s;
    vector<node> str;
    str.clear();
    int n;
    cin>>n;
    for(int i=0;i<n;i++)  {
    cin>>s.x>>s.y;;
    str.push_back(s);
    }
    sort(str.begin(),str.end(),gcd);
        for(int i=0;i<n;i++)  cout<<str[i].x<<str[i].y<<" ";
} 
View Code

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2021-11-17
  • 2021-06-30
  • 2022-12-23
  • 2021-09-03
  • 2021-05-17
猜你喜欢
  • 2021-12-28
  • 2021-12-18
  • 2021-12-18
  • 2021-08-15
  • 2022-01-03
  • 2022-01-18
  • 2022-12-23
相关资源
相似解决方案