answer01.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Please fill the functions in this file.
  3. * You can add additional functions.
  4. *
  5. * Hint:
  6. * You can write additonal functions.
  7. *
  8. * You may create additional arrays if needed. The maximum size
  9. * needed is specified by MAXLENGTH in pa01.h.
  10. */
  11. #include "pa01.h"
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. /*
  15. * =================================================================
  16. * This function prints all partitions of a positive integer value
  17. * See the file "expected/expected_unsorted" for the output specification
  18. */
  19. void partitionAll(int value)
  20. {
  21. printf("partitionAll %d\n", value);
  22. }
  23. /*
  24. * =================================================================
  25. * This function prints the partitions that use increasing values.
  26. *
  27. * For example, if value is 5
  28. * 2 + 3 and
  29. * 1 + 4 are valid partitions
  30. *
  31. * 5 is a valid partition
  32. *
  33. * 1 + 1 + 3 and
  34. * 2 + 1 + 2 and
  35. * 3 + 2 are invalid partitions.
  36. *
  37. * The program should generate only valid partitions. Do not
  38. * generates invalid partitions and checks validity before printing.
  39. *
  40. */
  41. void partitionIncreasing(int value)
  42. {
  43. printf("partitionIncreasing %d\n", value);
  44. }
  45. /*
  46. * =================================================================
  47. * This function prints the partitions that use unique values.
  48. *
  49. * For example, if value is 5
  50. * 2 + 3 and
  51. * 3 + 2 and
  52. * 1 + 4 are valid partitions
  53. *
  54. * 5 is a valid partition
  55. *
  56. * 1 + 1 + 3 and
  57. * 2 + 1 + 2 are invalid partitions.
  58. *
  59. * The program should generate only valid partitions. Do not
  60. * generates invalid partitions and checks validity before printing.
  61. *
  62. */
  63. void partitionUnique(int value)
  64. {
  65. printf("partitionUnique %d\n", value);
  66. }
  67. /*
  68. * =================================================================
  69. */
  70. void permute(char * charset, int len)
  71. {
  72. printf("permute %d\n", len);
  73. }