Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- int main()
- {
- int N,p,**post,i=-1,l,j=-1,pocitadlo=1,k,pomocne=0,o=-1,a=-2147483648,b=2147483647;
- char c;
- while((scanf("%d",&N)) > 0 )
- {
- if((N <= 1) || (N >= 30000))
- break;
- post = (int **) malloc((N+1) * sizeof(int *));
- for(k = 0; k <=N; k++)
- post[k] = (int *) malloc((N+1) * sizeof(int));
- for(k = 0; k<= N; k++)
- post[k][0]=0;
- while((scanf("%d",&p) > 0))
- {
- if((p < a) || (p > b))
- return 0;
- if(o == -1)
- {
- post[0][0]=p;
- post[0][1]=0;
- o++;
- }
- else
- {
- for(i = 0; i <= N; i++)
- {
- if((post[i][0] == 0) && (post[i+1][0] == 0))
- break;
- j=0;
- while(post[i][j+1] != 0)
- j++;
- if(p > post[i][j])
- {
- post[i][j+2]=post[i][j+1];
- post[i][++j]=p;
- break;
- }
- else
- {
- if(p < post[i][0])
- {
- for(k = j; k >=-1; k--)
- post[i][k+2]=post[i][k+1];
- post[i][0]=p;
- j++;
- break;
- }
- else
- {
- if((post[i+1][0] == 0) && (p <= post[i][j]) && (p >= post[i][0]))
- {
- post[i+1][1]=0;
- post[i+1][0]=p;
- pocitadlo++;
- break;
- }
- }
- }
- }
- }
- c=getchar();
- if(c == '\n')
- break;
- }
- printf("%d\n",pocitadlo);
- for(k = 0; k <=N; k++)
- {
- if(post[k][0] == 0)
- break;
- j=0;
- while((post[k][j] != 0))
- {
- printf("%d ",post[k][j]);
- j++;
- }
- // if((post[k][j] == 0) && (post[k+1][0] != 0))
- printf("\n");
- }
- for(k=0; k <= N; k++)
- free(post[k]);
- free(post);
- post = NULL;
- pocitadlo=1;
- o=-1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement