摘要: For example, given that the pattern ="abc", replace"abcdeffdfegabcabc"with"XdeffdfegX". Note that multiple occurrences ofabc's that are contiguous will be replaced with only one'X'. Solution:string& repalce(string& s, string ch) // the only problems 阅读全文
posted @ 2013-07-25 01:34 pgu2 阅读(199) 评论(0) 推荐(0)
摘要: Print all edge nodes of a complete binary tree anti-clockwise. That is all the left most nodes starting at root, then the leaves left to right and finally all the rightmost nodes. In other words, print the boundary of the tree.Variant: Print the same for a tree that is not complete.Solution:#include 阅读全文
posted @ 2013-07-18 21:54 pgu2 阅读(308) 评论(0) 推荐(0)
摘要: Given the sequenceS1= {a,b,c,d,...,x,y,z,aa,ab,ac.... } and given that this sequence corresponds (term for term) to the sequenceS2= {0,1,2,3,....}. Write code to convert an element ofS2to the corresponding element ofS1.solution:// ExcelSheetRowNumbers.cpp : Defines the entry point for the console ap 阅读全文
posted @ 2013-07-16 22:27 pgu2 阅读(182) 评论(0) 推荐(0)
摘要: Design an algorithm and write code to serialize and deserialize a binary tree.Writing the tree to a file is called 'serialization' and reading back from the file to reconstruct the exact same binary tree is 'deserialization'.Solution:// TreeSerialAndDeserial.cpp : Defines the entry p 阅读全文
posted @ 2013-07-13 04:58 pgu2 阅读(362) 评论(0) 推荐(0)
摘要: Given a singly linked list, find if there exist a loop.Solution:#include "stdafx.h"#include using namespace std;class Node{public: void addNode(Node* node); void loopStart(); void loopEnd(); void setVal(int val) {this->val = val;} int getVal() {return this->val;} Node(int val) {this- 阅读全文
posted @ 2013-07-08 21:20 pgu2 阅读(289) 评论(0) 推荐(0)
摘要: ProblemOn our planet, Jamcode IX, three Great Events occurred. They happened 26000, 11000 and 6000 slarboseconds ago. In 4000 slarboseconds, the amount of time since all of those events will be multiples of 5000 slarboseconds, the largest possible amount... and the apocalypse will come.Luckily for y 阅读全文
posted @ 2013-07-02 01:01 pgu2 阅读(210) 评论(0) 推荐(0)
摘要: Problemhttp://code.google.com/codejam/contest/dashboard?c=433101#s=p0TheSnapperis a clever little device that, on one side, plugs its input plug into an output socket, and, on the other side, exposes an output socket for plugging in a light or other device.When aSnapperis in the ON state and is rece 阅读全文
posted @ 2013-06-29 02:23 pgu2 阅读(198) 评论(0) 推荐(0)
摘要: Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.Solution:void putlong(unsigned long n){ if( n<10) { putchar(n%10+'0'); } else { putlong(n/10); putchar(n%10+'0'); } } For exa... 阅读全文
posted @ 2013-06-26 03:23 pgu2 阅读(161) 评论(0) 推荐(0)