Doubly linked list UVa12657 (not completed) Tle&&wa

Source: Internet
Author: User

1#include <iostream>2#include <cstring>3#include <cstdlib>4#include <cstdio>5 6 using namespacestd;7 8 structNode9 {Ten     intdate; Onenode*Next; Anode*Pre; -Node () {;p re=null;next=NULL;} - }; the  -InlineintScan () - { -     Charch; +     intA =0; -      while(ch = getchar ()) >='0'&& ch<='9') +A = A *Ten+ch-'0'; A     returnA; at } -  - intMain () - { -node* arr[200000]; -     intnum=1; in     intn,m; -node* tmp=NewNode (); tonode* head=NewNode (); +node* last=NewNode (); -      while(SCANF ("%d%d", &n,&m)! =EOF) the     { * GetChar (); $         intnum4=0;Panax Notoginsenghead->next=Last ; -Last->pre=head; the          for(intI=1; i<=n;i++) +         { Aarr[i]=Last ; theLast->date=i; +last->next=NewNode (); -Last->next->pre=Last ; $Last=last->Next; $last->next=NULL; -         } -         intorder; the         intb; -          for(intI=0; i<m;i++)Wuyi         { theOrder=Scan (); -             if(order==3) Wu             { -A=Scan (); Aboutb=Scan (); $node* Ta=Arr[a]; -node* tb=Arr[b]; -ta->pre->next=TB; -tb->pre->next=ta; ATa->next->pre=TB; +Tb->next->pre=ta; theTmp=ta->Pre; -Ta->pre=tb->Pre; $Tb->pre=tmp; theTmp=ta->Next; theTa->next=tb->Next; thetb->next=tmp; the             } -             Else if(order==2) in             { theA=Scan (); theb=Scan (); Aboutnode* Ta=Arr[a]; thenode* tb=Arr[b]; theTa->pre->next=ta->Next; theTa->next->pre=ta->Pre; +Ta->next=tb->Next; -Tb->next->pre=ta; thetb->next=ta;BayiTa->pre=TB; the             } the             Else if(order==1) -             { -A=Scan (); theb=Scan (); thenode* Ta=Arr[a]; thenode* tb=Arr[b]; theTa->pre->next=ta->Next; -Ta->next->pre=ta->Pre; theta->next=TB; theTa->pre=tb->Pre; thetb->pre->next=ta;94Tb->pre=ta; the             } the             Else if(order==4) the             {98num4++; About             } -         }101         Long Longreans=0;102         if(num4%2==0)103         {104node* ans =head->Next; the             intflag=1;106              while(ans->next!=NULL)107             {108                 if(flag)109                 { theReans+=ans->date;111                 } theflag=1-Flag;113Ans=ans->Next; the             } the         } the         Else117         {118node* ans =last->Pre;119             intflag=1; -              while(ans->pre!=NULL)121             {122                 if(flag)123                 {124Reans+=ans->date; the                 }126flag=1-Flag;127Ans=ans->Pre; -             }129         } theprintf"Case %d:%i64d\n", Num,reans);131        //cout<< "Case" <<num<< ":" <<reans<<endl; thenum++;133     }134     return 0;135}
View Code

Doubly linked list UVa12657 (not completed) Tle&&wa

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.