codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <stdio.h> #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0])) #define F(a,s) while(s--) *a=*a?*a++:*(a++-1) void printSolutions(int * solutions, int size) { do { printf("%d ", *solutions++); } while (--size > 0); printf("\n"); } int main(int argc, char * argv[]) { static int testCase1[] = {1, 0, 2, 0, 7, 7, 7, 0, 5, 0, 0, 0, 9}; static int testCase2[] = {1, 0, 0, 0, 0, 0}; static int testCase3[] = {-1, 0, 5, 0, 0, -7}; static int testCase4[] = {23, 0, 0, -42, 0, 0, 0}; static int testCase5[] = {1, 2, 3, 4}; static int testCase6[] = {-1234}; int * p; int s; printSolutions(testCase1, ARRAYSIZE(testCase1)); s = ARRAYSIZE(testCase1); p = testCase1; F(p, s); printSolutions(testCase1, ARRAYSIZE(testCase1)); printSolutions(testCase2, ARRAYSIZE(testCase2)); s = ARRAYSIZE(testCase2); p = testCase2; F(p, s); printSolutions(testCase2, ARRAYSIZE(testCase2)); printSolutions(testCase3, ARRAYSIZE(testCase3)); s = ARRAYSIZE(testCase3); p = testCase3; F(p, s); printSolutions(testCase3, ARRAYSIZE(testCase3)); printSolutions(testCase4, ARRAYSIZE(testCase4)); s = ARRAYSIZE(testCase4); p = testCase4; F(p, s); printSolutions(testCase4, ARRAYSIZE(testCase4)); printSolutions(testCase5, ARRAYSIZE(testCase5)); s = ARRAYSIZE(testCase5); p = testCase5; F(p, s); printSolutions(testCase5, ARRAYSIZE(testCase5)); printSolutions(testCase6, ARRAYSIZE(testCase6)); s = ARRAYSIZE(testCase6); p = testCase6; F(p, s); printSolutions(testCase6, ARRAYSIZE(testCase6)); return 0; }
Private
[
?
]
Run code
Submit