Skip to content

Instantly share code, notes, and snippets.

@smalinux
Last active March 18, 2019 21:01
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 smalinux/494c97457a00758e7a7b14785c8ad92c to your computer and use it in GitHub Desktop.
Save smalinux/494c97457a00758e7a7b14785c8ad92c to your computer and use it in GitHub Desktop.
Quick reference for my codeforces solutions
#include<bits/stdc++.h>
using namespace std;
int main() {
// https://en.cppreference.com/w/cpp/utility/pair/operator_cmp
// ----- Output -------
// (1,foo)
// (2,bar)
// (2,baz)
// ---------------------------------------------------------------------------------------------------
std::vector<std::pair<int, std::string>> v = { {2, "baz"},
{2, "bar"},
{1, "foo"} };
std::sort(v.begin(), v.end());
for(auto p: v) {
std::cout << "(" << p.first << "," << p.second << ")\n";
}
// ---------------------------------------------------------------------------------------------------
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
int x = 24;
int age;
string name, gender;
float height;
int wedith;
std::vector<tuple<string, int, string, float, int>> v;
for (auto i = 0; i < 3; ++i)
{
cin >> age >> name >> gender >> height >> wedith;
v.push_back( make_tuple ( name, age, gender, height, wedith ) );
}
sort( v.begin(), v.end() );
for (auto i = 0; i != v.size(); ++i)
{
cout << get<0>( v[i] ) << " " << get<1>( v[i] ) << " "<< get<2>( v[i] ) << " "<< get<3>( v[i] ) << " "<< get<4>( v[i] ) << "\n";
}
// ---------------------------------------------------------------------------------------------------
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
// Thanks : http://www.cplusplus.com/reference/tuple/tuple/
//
// ---------------------------------------------------------------------------------------------------
// Name, Age, Gender, Height, Weight
auto s1 = make_tuple( "Lisa Simpson", 24, "Female", 1.7F, 60 );
auto s2 = make_tuple( "Bart Simpson", 25, "Male", 1.8F, 80 );
cout << get<0>( s2 ); // s2 > Name
cout << '\n'; // ----------
cout << get<2>( s2 ); // s2 > Gender
cout << '\n'; // ----------
get<4>( s2 ) = 800; // Access & change
cout << get<4>( s2 ); // s2 > Gender
cout << '\n'; // ----------
cout << tuple_size<decltype( s2 )>::value; // num of tuple elements
cout << '\n'; // ----------
// ---------------------------------------------------------------------------------------------------
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main() {
// Example 1 - tuple
// tuple : https://en.cppreference.com/w/cpp/utility/tuple
// ---------------------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------------------
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment