juchem / prep Goto Github PK
View Code? Open in Web Editor NEWCoding exercises to stay in shape.
Coding exercises to stay in shape.
#include <iostream>
#include <type_traits>
#include <iterator>
#include <vector>
using namespace std;
template<typename T>
void genseq(T start, T end, int tam);
int main()
{
char master[] = {'a','b','c','d','e'};
for( int s = 0; s <= 6; ++s ) {
genseq(master,master+5,s);
}
}
// need one n sized subsequence starting at each element of the master sequence
// n sized subsequences starting in X are X + all n-1 sized subsequences after X
// a 0 sized subsequence defines its ending
// n sized subsequences starting in X when there are less than n-1 elements
after X are discarded
template<typename T>
void genseq2(T start, T end, int tam, vector<typename
iterator_traits<T>::value_type> & seq)
{
if( tam == 0 ) {
// emit seq and return
copy(seq.begin(),seq.end(),ostream_iterator<typename iterator_traits<T>::value_type>(cout,","));
cout << endl;
return;
}
for( T x = start; x != end-tam+1; ++x ) {
seq.push_back(*x);
genseq2(x+1,end,tam-1,seq);
seq.pop_back();
}
}
template<typename T>
void genseq(T start, T end, int tam)
{
cout << "generating sequences for size " << tam << endl;
if( tam <= 0 || end-start < tam ) return;
vector<typename iterator_traits<T>::value_type> seq;
genseq2(start, end, tam, seq);
}
Original issue reported on code.google.com by [email protected]
on 20 Jul 2012 at 4:46
What steps will reproduce the problem?
1.
Input:
0 4 1
1 1 1
2 1 2
What is the expected output? What do you see instead?
The result should be: 8
The actual result is: 10
Version:
http://ideone.com/oYg0Fq
Please provide any additional information below.
It looks like there's a bug while removing the element from the bst when two or
more elements have the same height
Original issue reported on code.google.com by vdeantoni
on 25 Mar 2013 at 7:28
int treeSum(TreeNode * node) {
if( ! node ) return 0;
return node->value += treeSum(node->left) + treeSum(node->right);
}
Original issue reported on code.google.com by [email protected]
on 13 Jul 2012 at 6:15
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.