Skip to content

Instantly share code, notes, and snippets.

View kLiHz's full-sized avatar

kLiHz kLiHz

View GitHub Profile
@kLiHz
kLiHz / year_of_the_cow.cpp
Created May 23, 2021 08:56
USACO21 FEB BRONZE
#include <iostream>
#include <map>
#include <string>
// Assume Cow B in each line appeared before
class Solution {
public:
enum class Relation {BEFORE, AFTER};
enum class Zodiac {
@kLiHz
kLiHz / passage.txt
Last active May 12, 2021 15:40
Find word in a file.
Next to a great forest there lived a poor woodcutter with his wife and his two children.
The boy's name was Hansel and the girl's name was Gretel. He had but little to eat, and
once, when a great famine came to the land, he could no longer provide even their daily
bread.
One evening as he was lying in bed worrying about his problems, he sighed and said to his
wife, "What is to become of us? How can we feed our children when we have nothing for
ourselves?"
"Man, do you know what?" answered the woman. "Early tomorrow morning we will take the two
@kLiHz
kLiHz / print_I64.cpp
Last active December 24, 2020 19:08
Convert signed 64-bit int
#include <iostream>
#include <chrono>
void print_I64(long long num) {
// Try NOT using `if` statement, since it will make the program slower
char str[32] = {0};
short idx = 31;
long long sign = num >> 63; // -1 for negative, 0 for positive
// by doing this we assume that the spaces are filled with num's sign bit
num ^= sign;