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
#! /bin/bash | |
if [ $# -lt 2 ]; then | |
echo Usage: $0 TARGET INPUT1 [...] | |
exit 0 | |
fi | |
DIR=$(dirname $0) | |
target=$1 | |
shift |
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
import md5 | |
import sys | |
if __name__ == '__main__': | |
if len(sys.argv) < 2: | |
print 'Usage: %s hex_str' % sys.argv[0] | |
hex_str = sys.argv[1] | |
mem = bytearray(len(hex_str) / 2) | |
for i in xrange(len(hex_str) / 2): |
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
import sys | |
a, b = sys.argv[1:] | |
print float(a) / float(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
struct Node | |
{ | |
Node* next; | |
Node* random; | |
int data; | |
Node(const Node& n) | |
: next(NULL), random(NULL), data(n.data) | |
{} | |
}; |
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
(define flatten (seq) | |
(cond (((null? seq) '()) | |
((pair? (car seq)) (append (flatten (car seq)) | |
(flatten (cdr seq)))) | |
(else (cons (car seq) (flatten (cdr seq))))))) | |
(define append (l1 l2) | |
(if (null? l1) | |
l2 | |
(cons (car l1) (append (cdr l1) l2)))) |
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
string a; | |
string b; | |
string c; | |
bool is_interleave(const string& sa, const string& sb, const string& sc) | |
{ | |
if (sc.size() != sa.size() + sb.size()) | |
{ | |
return false; | |
} |
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
// in-fix to post-fix expression | |
typedef vector<string> Expr; | |
void transform(const Expr& infix, Expr& result) | |
{ | |
stack<string> ops; | |
for (int i = 0; i < infix.size(); ++i) | |
{ | |
if (infix[i] == "*" || infix[i] == "/") |
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
typedef vector<char> BinaryNum; | |
void binary_num(int n, vector<BinaryNum>& results) | |
{ | |
if (n < 1) | |
{ | |
return; | |
} | |
BinaryNum tmp(n, 0); |
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
// | |
bool knows(const int i, const int j) | |
{ | |
// xxxx | |
return true; | |
} | |
int celerity(vector<int>& person) | |
{ |
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
// solution 1: count the nodes of left and right subtree, and add them up | |
int node_count(Node* node) | |
{ | |
if (node == NULL) | |
{ | |
return 0; | |
} | |
return node_count(node->left) + node_count(node->right) + 1; | |
} |