Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Python to C++

Name: Anonymous 2012-11-11 13:29

Can someone convert this python code into C++ please?


#!/usr/bin/python

# find the number of ways to reach a total with the given number of combinations

cents = 200
denominations = [25, 10, 5, 1]
names = {25: "quarter(s)", 10: "dime(s)", 5 : "nickel(s)", 1 : "pennies"}

def count_combs(left, i, comb, add):
    if add: comb.append(add)
    if left == 0 or (i+1) == len(denominations):
        if (i+1) == len(denominations) and left > 0:
            comb.append( (left, denominations[i]) )
            i += 1
        while i < len(denominations):
            comb.append( (0, denominations[i]) )
            i += 1
        print " ".join("%d %s" % (n,names[c]) for (n,c) in comb)
        return 1
    cur = denominations[i]
    return sum(count_combs(left-x*cur, i+1, comb[:], (x,cur)) for x in range(0, int(left/cur)+1))

print count_combs(cents, 0, [], None)



Thanks in advance

Name: Anonymous 2012-11-11 13:30

Name: Anonymous 2012-11-11 13:34

very funny.

Name: Anonymous 2012-11-11 13:39

>>1
Good Joke Anon I Lol'd Xd

Name: Anonymous 2012-11-11 14:09

>not using javascript

enjoy your slow-ass c++ getting raped by v8

Name: Anonymous 2012-11-11 14:37

>>5
javashit troll

back to hacker jews

Name: Anonymous 2012-11-11 14:42

{25: "quarter(s)", 10: "dime(s)", 5 : "nickel(s)", 1 : "pennies"}

well

Name: Anonymous 2012-11-11 15:29

pypy

Name: Anonymous 2012-11-11 16:00

just use py2sepples.

Name: Anonymous 2012-11-11 16:14

>>27
[None, "pennies", None, None, None, "nickel(s)", None, None, None, None, "dime(s)", None, None, None, None, None, None, None, None, None, None, None, None, None, None, "quarter(s)"]

WINAPI QUALITY

Name: Anonymous 2012-11-11 16:14

#include <iostream>

int main(){
    int a, b, c, n = 0;
    for (a = 200; a >= 0; a -= 25)
    for (b =   a; b >= 0; b -= 10)
    for (c =   b; c >= 0; c -=  5) n++;
    std::cout << n;
}

Name: Anonymous 2012-11-11 18:15

Why does anyone still use anything but C? Enjoy your slow-as-dogshit non-portable programs.

Name: Anonymous 2012-11-11 18:25

>>12
Wait until the Javashit troll comes to this thread.

Name: Anonymous 2012-11-11 20:23

>>12
Because C is undefined shit, read the fucking /prog/ manual.

Name: Anonymous 2012-11-11 20:37

>>11
lolno

Name: Anonymous 2012-11-13 3:38

Name: Anonymous 2012-11-13 4:48

Name: Anonymous 2012-11-13 8:31

lol python. Use a real programming language, like javascript

Name: !Ykx/satorI 2012-11-13 9:10

Name: Anonymous 2012-11-13 9:14

>>18
javashit is shit

Name: Anonymous 2012-11-13 13:46

/polecat kebabs/

Name: Anonymous 2012-11-19 15:20

non-dubs to dubs
check 'em

Name: Anonymous 2012-11-19 17:14

why are you thanking me in advance? i'm not going to do it.

Don't change these.
Name: Email:
Entire Thread Thread List