Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cctype>
- #include <cstdlib>
- using namespace std;
- typedef struct nod
- {
- int l,c,x;
- struct nod*ant,*urm;
- }NOD;
- NOD *p1,*u1;
- FILE *f=fopen("date.in","r");
- FILE *g=fopen("date.in","w");
- NOD *caut(NOD *p,NOD *u,int l,int c)
- {
- NOD*q;
- p=q;
- while(q!=NULL)
- {
- if(q->l==l && q->c==c)
- return NULL;
- if(q->l>l)
- return q;
- if(q->l==l && q->c>c)
- return q;
- q=q->urm;
- }
- }
- void adaug(NOD *&p,NOD *&u,int l,int c,int x)
- {
- NOD *q,*r;
- r=(NOD*)malloc(sizeof(NOD));
- r->ant=r->urm=NULL;
- r->l=l;
- r->c=c;
- r->x=x;
- if(p==NULL)
- p=u=r;
- else if((r->l<p->l) || r->l==p->l && r->c<p->c)
- {
- u->urm=p;
- r->ant=r;
- p=r;
- }
- else if(r->l>u->l || r->l==u->l && r->c>u->c)
- {
- u->urm=r;
- r->ant=u;
- u=r;
- }
- else
- {
- q=caut(p,u,l,c);
- if(q==NULL)
- free(r);
- else
- {
- r->urm=q;
- r->ant=q->ant;
- q->ant->urm=r;
- q->ant=r;
- }
- }
- }
- void creare(NOD*&p,NOD*&u,int n)
- {
- int x,y,z,i,m;
- fscanf(f,"%d%d",&n,&m);
- for(i=1;i<=m;i++)
- {
- fscanf(f,"%d%d%d",&x,&y,&z);
- adaug(p,u,x,y,z);
- }
- }
- void afis_mat(NOD *p,NOD *u,int n)
- {
- NOD *q;
- q=p;
- int i,j,OK;
- for(i=1;i<=n;i++)
- {
- for(j=1;j<=n;j++)
- {
- q=p;
- OK=0;
- while(q!=NULL)
- if(i==q->l && j==q->c)
- {
- printf("%4d",q->x);
- OK=1;
- break;
- }
- q=q->urm;
- }
- if(OK==0)
- printf("%4d",0);
- printf("\n");
- }
- }
- int main()
- {
- int n;
- creare(p1,u1,n);
- afis_mat(p1,u1,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement