Guest User

Untitled

a guest
Feb 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. void rm(char *code, int n){
  6. char *buf;
  7.  
  8. if(n == 0){
  9. printf("%s\n", code);
  10. return;
  11. }
  12.  
  13. buf = malloc(strlen(code)+2);
  14.  
  15. strcpy(buf, code);
  16. strcat(buf, ".");
  17. rm(buf, n-1);
  18.  
  19. if(n >= 2){
  20. strcpy(buf, code);
  21. strcat(buf, "-");
  22. rm(buf, n-2);
  23. }
  24.  
  25. free(buf);
  26. }
  27.  
  28.  
  29. int main(int argc, char *argv[]){
  30. int len;
  31.  
  32. if(argc != 2){
  33. printf("usage: %s n\n", argv[0]);
  34. return 1;
  35. }
  36.  
  37. len = atoi(argv[1]);
  38.  
  39. if(len <= 0){
  40. printf("n must be integer >= 1\n");
  41. return 1;
  42. }
  43.  
  44. rm("", len);
  45.  
  46. return 0;
  47. }
Add Comment
Please, Sign In to add comment