Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- struct node
- {
- int data;
- struct node *right,*left,*top,*bottom;
- };
- struct node *head=NULL,*temp,*s,*s1,*s2,*s3;
- int main()
- {
- int n,a,top=0,bottom=0,right=0,left=0;
- char d;
- cin>>n;
- head=(struct node*) malloc (sizeof(struct node));
- head->right=NULL;
- head->left=NULL;
- head->top=NULL;
- head->bottom=NULL;
- s=head;
- s1=head;
- s2=head;
- s3=head;
- for(int i=1; i<=n; i++)
- {
- struct node *newnode;
- newnode=(struct node*) malloc (sizeof(struct node));
- cin>>d;
- cin>>a;
- if(d=='L')
- {
- newnode->data=a;
- left+=a;
- newnode->left=NULL;
- s->left=newnode;
- s=newnode;
- }
- else if(d=='R')
- {
- newnode->data=a;
- right+=a;
- newnode->right=NULL;
- s1->right=newnode;
- s1=newnode;
- }
- else if(d=='T')
- {
- newnode->data=a;
- top+=a;
- newnode->left=NULL;
- s2->top=newnode;
- s2=newnode;
- }
- else if(d=='B')
- {
- newnode->data=a;
- bottom+=a;
- newnode->bottom=NULL;
- s3->bottom=newnode;
- s3=newnode;
- }
- }
- int b[4];
- b[0]=top;
- b[1]=bottom;
- b[2]=left;
- b[3]=right;
- sort(b,b+4);
- if(b[3]==top)
- {
- cout<<"Top link list has maximum sum "<<b[3]<<endl;
- }
- if(b[3]==bottom)
- {
- cout<<"Bottom link list has maximum sum "<<b[3]<<endl;
- }
- if(b[3]==right)
- {
- cout<<"Right link list has maximum sum "<<b[3]<<endl;
- }
- if(b[3]==left)
- {
- cout<<"Left link list has maximum sum "<<b[3]<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement