Skip to content

Instantly share code, notes, and snippets.

@lispc
Created May 24, 2014 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lispc/13993fd7d1211bee5627 to your computer and use it in GitHub Desktop.
Save lispc/13993fd7d1211bee5627 to your computer and use it in GitHub Desktop.
C++
#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<utility>
#include<unistd.h>
#include<algorithm>
using namespace std;
struct Result{
int position;
int length;
Result(int position,int length){
this->position = position;
this->length = length;
}
void show() const{
cout<<position<<" "<<length<<endl;
}
};
bool _comp(const Result & a,const Result & b){
//cout<<"<=="<<endl;
//a.show();
//b.show();
//cout<<"==>"<<endl;
if(a.position<b.position)
return true;
if(a.length<b.length)
return true;
return false;
}
int main(int argc,char** argv){
vector<Result> global_res;
global_res.push_back(Result(15,15));
global_res.push_back(Result(15,16));
global_res.push_back(Result(14,17));
global_res.push_back(Result(15,17));
global_res.push_back(Result(14,18));
global_res.push_back(Result(13,19));
global_res.push_back(Result(15,18));
for(int i=0;i<global_res.size();i++){
global_res[i].show();
}
cout<<"=="<<endl;
sort(global_res.begin(),global_res.end(),_comp);
for(int i=0;i<global_res.size();i++){
global_res[i].show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment