Advertisement
josiftepe

Untitled

Apr 18th, 2021
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define INT_MAX 2147483647
  5. int main() {
  6. char *c;
  7. c = (char*) malloc(3 * sizeof(char));
  8. int **arr;
  9. int rows = 0;
  10. while(1) {
  11. scanf("%s", c);
  12. if(strcmp(c, "AFR") == 0) {
  13. int n, *a;
  14. scanf("%d", &n);
  15. a = (int*) malloc(n * sizeof(int));
  16. for(int i = 0; i < n; i++) {
  17. scanf("%d", (a + i));
  18. }
  19. if(rows == 0) {
  20. arr = (int**) malloc(sizeof(int*));
  21. *(arr) = (int*) malloc((n + 1) * sizeof(int));
  22. for(int i = 0; i < n; i++) {
  23. *(*(arr) + i) = *(a + i);
  24. }
  25. *(*(arr) + n) = -INT_MAX;
  26. }
  27. else {
  28. int **tmp = (int**) malloc((rows) * sizeof(int*));
  29. for(int i = 1; i < rows; i++) {
  30. int *ptr = *(arr);
  31. int j = 0;
  32. *(tmp + i - 1) = (int*) malloc(sizeof(int) * 100);
  33. while(*ptr != -INT_MAX) {
  34. *(*(tmp + i - 1) + j) = *ptr;
  35. j++;
  36. ptr++;
  37. }
  38. }
  39. arr = (int**) malloc((rows + 1) * sizeof(int*));
  40. for(int i = 0; i < rows; i++) {
  41. int h = 0;
  42. int *ptr = *(tmp);
  43. while(ptr != NULL && *ptr != -INT_MAX) {
  44. ptr++;
  45. h++;
  46. }
  47. *(arr + i) = (int*) malloc((h + 1) * sizeof(int));
  48. for(int j = 0; j < h; j++) {
  49. *(*(arr + i + 1) + j) = *(*(tmp + i) + j);
  50. }
  51. }
  52. *(arr) = (int*)malloc(sizeof(int) * (n + 1));
  53. for(int j = 0; j < n; j++) {
  54. *(*(arr) + j) = *(a + j);
  55. }
  56. *(*(arr) + n) = -INT_MAX;
  57.  
  58. }
  59. rows++;
  60.  
  61. }
  62. for(int i = 0; i < rows; i++) {
  63. int *ptr = *(arr + i);
  64. int sz = sizeof((arr + i)) / sizeof(int);
  65. printf("%d ", sz);
  66. for(int j = 0; j < sz; j++) {
  67. printf("%d ", *(*(arr + i) + j));
  68. }
  69. printf("\n");
  70. }
  71. }
  72.  
  73. return 0;
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement