This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
inline int max(int a, int b) { | |
return a > b ? a : b; | |
} | |
int trunc(int v) { | |
if (abs(v) == 1) return abs(v); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using std::max; | |
// Let A be an array of length N | |
// Let M(i) be the largest contiguous subsequence ending at index i | |
// M(0) = 1 | |
// M(i) = max(M(i),M(j)+1) for j<i and A[j]<=A[i] | |
int maxSubArray(int A[], int N) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <streambuf> | |
#include <iostream> | |
#include <fstream> | |
#include <stdexcept> | |
#include <utility> | |
#include <string> | |
#include <vector> | |
#include <cctype> | |
#include <memory> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <sstream> | |
std::string UnaryToBinary(std::string str) { | |
std::string binary; | |
binary.reserve(30); | |
char flag; | |
for (std::stringstream ss(str); ss >> str; ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstring> | |
#include <stack> | |
uint8_t precedence[256]; | |
bool HasHigherPrecedence(char a, char b) { | |
return precedence[(uint8_t)a] < precedence[(uint8_t)b]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <utility> | |
#include <tuple> | |
namespace detail { | |
template<class... Args> | |
struct stream_bump { | |
std::tuple<Args...> args; | |
template<class F> | |
void operator->*(F&& f) && { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <utility> | |
template<class T> struct TD; | |
template<class T> void f(T&& x) { TD<decltype(x)>(); } | |
// T & = T& | |
// T && = T&& | |
// T& & = T& | |
// T& && = T& |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
#include <algorithm> | |
template<class charT> | |
struct word_inserter_impl { | |
word_inserter_impl(int words, std::basic_string<charT>& str, charT delim) | |
: str_(str) | |
, delim_(delim) | |
, words_(words) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <iostream> | |
#include <initializer_list> | |
enum struct Color { | |
red,blue,orange,purple,green,black,yellow,invalid=-1 | |
}; | |
Color FromStringToColor(std::string const& str) { | |
return ((str == "red") ? Color::red : |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <cctype> | |
#include <cassert> | |
namespace detail { | |
bool isMatchingPair(char c1, char c2) { | |
return std::isupper(c1) && std::tolower(c1) == c2; | |
} | |
} |