Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define INT_MAX 2147483647
- int main() {
- char *c;
- c = (char*) malloc(3 * sizeof(char));
- int **arr;
- int rows = 0;
- while(1) {
- scanf("%s", c);
- if(strcmp(c, "AFR") == 0) {
- int n, *a;
- scanf("%d", &n);
- a = (int*) malloc(n * sizeof(int));
- for(int i = 0; i < n; i++) {
- scanf("%d", (a + i));
- }
- if(rows == 0) {
- arr = (int**) malloc(sizeof(int*));
- *(arr) = (int*) malloc((n + 1) * sizeof(int));
- for(int i = 0; i < n; i++) {
- *(*(arr) + i) = *(a + i);
- }
- *(*(arr) + n) = -INT_MAX;
- }
- else {
- int **tmp = (int**) malloc((rows) * sizeof(int*));
- for(int i = 1; i < rows; i++) {
- int *ptr = *(arr);
- int j = 0;
- *(tmp + i - 1) = (int*) malloc(sizeof(int) * 100);
- while(*ptr != -INT_MAX) {
- *(*(tmp + i - 1) + j) = *ptr;
- j++;
- ptr++;
- }
- }
- arr = (int**) malloc((rows + 1) * sizeof(int*));
- for(int i = 0; i < rows; i++) {
- int h = 0;
- int *ptr = *(tmp);
- while(ptr != NULL && *ptr != -INT_MAX) {
- ptr++;
- h++;
- }
- *(arr + i) = (int*) malloc((h + 1) * sizeof(int));
- for(int j = 0; j < h; j++) {
- *(*(arr + i + 1) + j) = *(*(tmp + i) + j);
- }
- }
- *(arr) = (int*)malloc(sizeof(int) * (n + 1));
- for(int j = 0; j < n; j++) {
- *(*(arr) + j) = *(a + j);
- }
- *(*(arr) + n) = -INT_MAX;
- }
- rows++;
- }
- for(int i = 0; i < rows; i++) {
- int *ptr = *(arr + i);
- int sz = sizeof((arr + i)) / sizeof(int);
- printf("%d ", sz);
- for(int j = 0; j < sz; j++) {
- printf("%d ", *(*(arr + i) + j));
- }
- printf("\n");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement