Skip to content

Instantly share code, notes, and snippets.

@sturgle
sturgle / SquareDetector
Last active December 29, 2015 01:59
Square Detector
#include <vector>
#include <iostream>
#include <string>
using namespace std;
int main()
{
int kase;
cin>> kase;
for (int k = 1; k <= kase; k++)
/*
http://www.careercup.com/question?id=19300678
If a=1, b=2, c=3,....z=26. Given a string, find all possible codes that string can generate. Give a count as well as print the strings.
For example:
Input: "1123". You need to general all valid alphabet codes from this string.
Output List
aabc //a = 1, a = 1, b = 2, c = 3
kbc // since k is 11, b = 2, c= 3
/*
http://www.careercup.com/question?id=12986664
Push all the zero's of a given array to the end of the array. In place only. Ex 1,2,0,4,0,0,8 becomes 1,2,4,8,0,0,0
*/
#include <vector>
#include <iostream>
using namespace std;
void putZeroToEnd(vector<int> &vec) {
// i for next non-zero num index
// j for normal move forward index
/*
http://www.careercup.com/question?id=12718665
String Reduction
Given a string consisting of a,b and c's, we can perform the following operation: Take any two adjacent distinct characters and replace it with the third character. For example, if 'a' and 'c' are adjacent, they can replaced with 'b'. What is the smallest string which can result by applying this operation repeatedly?
Sample Input:
cab
bcab
ccccc
/*
http://www.careercup.com/question?id=23594662
Given a sequence of numbers A(1) ..A(n), find the continuous subsequenceA(i)..A(j) for which the sum of elements is maximum.
condition: we should not select two contiguous numbers
Solution:
Dp: F[i] = max(A[i], A[i] + F[i-2], F[i-1])
*/
#include <vector>
#include <iostream>
/*
http://www.careercup.com/question?id=9820788
there is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 and so on..
It looks something like this
1
2 3
4 5 6
every cup has capacity C. you pour L liters of water from top . when cup 1 gets filled , it overflows to cup 2,3 equally, and when they get filled , Cup 4 and 6 get water only from 2 and 3 resp but 5 gets water from both the cups and so on.
Now given C and M .Find the amount of water in ith cup.
/*
http://www.careercup.com/question?id=15645665
Find the k'th largest element in a binary search tree.
*/
#include <stack>
#include <iostream>
using namespace std;
struct Node {
int val;
@sturgle
sturgle / TurnToList.cpp
Last active August 29, 2015 13:57
TurnFileWithNumberToList
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
struct ListNode {
int val;
ListNode *next;
ListNode(int _val) {
val = _val;
@sturgle
sturgle / Crawler.py
Last active August 29, 2015 13:58
A crawler to get books on douban, but it seems not working as douban will block it after a while.
#!/usr/bin/env python
# coding=utf-8
from sys import argv
from string import replace,find,lower
from htmllib import HTMLParser
from urllib import urlretrieve, urlopen
from urlparse import urlparse,urljoin
from formatter import DumbWriter,AbstractFormatter
from cStringIO import StringIO
@sturgle
sturgle / getEd2kLinks.py
Last active August 29, 2015 13:58
Get Ed2k links from a web page