fork download
  1. #include <stdio.h>
  2.  
  3. #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
  4. #define F(a,s) while(s--) *a=*a?*a++:*(a++-1)
  5.  
  6. void printSolutions(int * solutions, int size)
  7. {
  8. do {
  9. printf("%d ", *solutions++);
  10. } while (--size > 0);
  11. printf("\n");
  12. }
  13.  
  14. int main(int argc, char * argv[])
  15. {
  16. static int testCase1[] = {1, 0, 2, 0, 7, 7, 7, 0, 5, 0, 0, 0, 9};
  17. static int testCase2[] = {1, 0, 0, 0, 0, 0};
  18. static int testCase3[] = {-1, 0, 5, 0, 0, -7};
  19. static int testCase4[] = {23, 0, 0, -42, 0, 0, 0};
  20. static int testCase5[] = {1, 2, 3, 4};
  21. static int testCase6[] = {-1234};
  22. int * p;
  23. int s;
  24. printSolutions(testCase1, ARRAYSIZE(testCase1));
  25. s = ARRAYSIZE(testCase1);
  26. p = testCase1;
  27. F(p, s);
  28. printSolutions(testCase1, ARRAYSIZE(testCase1));
  29. printSolutions(testCase2, ARRAYSIZE(testCase2));
  30. s = ARRAYSIZE(testCase2);
  31. p = testCase2;
  32. F(p, s);
  33. printSolutions(testCase2, ARRAYSIZE(testCase2));
  34. printSolutions(testCase3, ARRAYSIZE(testCase3));
  35. s = ARRAYSIZE(testCase3);
  36. p = testCase3;
  37. F(p, s);
  38. printSolutions(testCase3, ARRAYSIZE(testCase3));
  39. printSolutions(testCase4, ARRAYSIZE(testCase4));
  40. s = ARRAYSIZE(testCase4);
  41. p = testCase4;
  42. F(p, s);
  43. printSolutions(testCase4, ARRAYSIZE(testCase4));
  44. printSolutions(testCase5, ARRAYSIZE(testCase5));
  45. s = ARRAYSIZE(testCase5);
  46. p = testCase5;
  47. F(p, s);
  48. printSolutions(testCase5, ARRAYSIZE(testCase5));
  49. printSolutions(testCase6, ARRAYSIZE(testCase6));
  50. s = ARRAYSIZE(testCase6);
  51. p = testCase6;
  52. F(p, s);
  53. printSolutions(testCase6, ARRAYSIZE(testCase6));
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
1 0 2 0 7 7 7 0 5 0 0 0 9 
1 1 1 1 1 1 1 1 1 1 1 1 1 
1 0 0 0 0 0 
1 1 1 1 1 1 
-1 0 5 0 0 -7 
-1 -1 -1 -1 -1 -1 
23 0 0 -42 0 0 0 
23 23 23 23 23 23 23 
1 2 3 4 
1 1 1 1 
-1234 
-1234