Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Algorithms/syntax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ cout << __builtin_ctz(x) << "\n"; // 4 zeroes at the end of the number
cout << __builtin_popcount(x) << "\n"; // 5 ones
cout << __builtin_parity(x) << "\n"; // 1

//Append ll to the end for this to apply to long longs.
// Append ll to the end for this to apply to long longs.

// Set operations:
// a & b: intersection
// a | b: union
// ~a: complement
// a & (~b): difference

//ordered set
// ordered set

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
Expand All @@ -33,25 +33,25 @@ s.insert(9);
auto x = s.find_by_order(2);
cout << *x << "\n"; // 7

//And the function order_of_key returns the position of a given element:
// And the function order_of_key returns the position of a given element:

cout << s.order_of_key(7) << "\n"; // 2

//If the element does not appear in the set, we get the position that the element
//would have in the set:
// If the element does not appear in the set, we get the position that the element
// would have in the set:

cout << s.order_of_key(6) << "\n"; // 2
cout << s.order_of_key(8) << "\n"; // 3

//Converting from int to string
// Converting from int to string

int n = 1;
string result;
ostringstream oss;
oss << n;
result = oss.str();

//string to int
// string to int

string text = "456";
int num;
Expand All @@ -60,19 +60,19 @@ if(!(iss >> num)) {
num = 0;
}

//Process words from a line (useful when the length of a line is not specified beforehand)
// Process words from a line (useful when the length of a line is not specified beforehand)
string s;
getline(cin, s);
stringstream ss;
ss << s;
string s2;
while(ss >> s2) {
//process s2
// process s2
}

//randomization (source: https://codeforces.com/blog/entry/61587)
// randomization (source: https://codeforces.com/blog/entry/61587)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<> distrib1(1, n);
int x = big-get(distrib1(rng));
//can change to mt19937_64 for long longs
// can change to mt19937_64 for long longs