Advertisement
wojiaocbj

linkedlist

Oct 2nd, 2022
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.42 KB | None | 0 0
  1. /*
  2.  Author: 曹北健
  3.  Result: AC Submission_id: 4432711
  4.  Created at: Fri May 13 2022 19:31:52 GMT+0800 (China Standard Time)
  5.  Problem_id: 5758   Time: 719   Memory: 2816
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13. #pragma warning(disable:4996)
  14. typedef long long s64, LL;
  15. typedef unsigned long long u64, ULL;
  16. typedef struct node{
  17.     char name[52];
  18.     char gender[8];
  19.     int id;
  20.     LL tel;
  21.     struct node *next;
  22. }node;
  23. node linkedlist[114514] = { 0 }, *head, *tail;
  24. int unused = 0;
  25. int main(){
  26. #ifdef _DEBUG
  27.     FILE *fp = freopen("../../../input.txt", "r", stdin);
  28.     //FILE *fp2 = freopen("../../../output.txt", "w", stdout);
  29. #endif // _DEBUG
  30.     int n, m, op, tmpid;
  31.     char tmpname[52] = { 0 }, tmpgender[8] = { 0 };
  32.     LL tmptel;
  33.     node *cur;
  34.     scanf("%d%d", &n, &m);
  35.     for(unused = 0; unused < n; unused++){
  36.         scanf("%s%d%s%lld", linkedlist[unused].name, &linkedlist[unused].id, linkedlist[unused].gender, &linkedlist[unused].tel);
  37.         linkedlist[unused].next = linkedlist + unused + 1;
  38.     }
  39.     linkedlist[n - 1].next = 0;
  40.     head = linkedlist;
  41.     tail = linkedlist + n - 1;
  42.     while(m--){
  43.         scanf("%d", &op);
  44.         switch(op){
  45.         case 1:
  46.             //scanf("%s%d%s%lld", tmpname, &tmpid, tmpgender, &tmptel);
  47.             //addtail(tmpname, tmpgender, tmpid, tmptel);
  48.             scanf("%s%d%s%lld", linkedlist[unused].name, &linkedlist[unused].id, linkedlist[unused].gender, &linkedlist[unused].tel);
  49.             //linkedlist[unused].next = 0;
  50.             tail->next = linkedlist + unused;
  51.             tail = tail->next;
  52.             unused++;
  53.             break;
  54.         case 2:
  55.             scanf("%d%lld", &tmpid, &tmptel);
  56.             //updatetel(tmpid, tmptel);
  57.             cur = head;
  58.             while(cur && cur->id != tmpid){
  59.                 cur = cur->next;
  60.             }
  61.             cur->tel = tmptel;
  62.             break;
  63.         case 4:
  64.             //scanf("%s%d%s%lld%d", tmpname, &tmpid, tmpgender, &tmptel, &tmpid2);
  65.             //addafter(tmpname, tmpgender, tmpid, tmptel, tmpid2);
  66.             scanf("%s%d%s%lld%d", linkedlist[unused].name, &linkedlist[unused].id, linkedlist[unused].gender, &linkedlist[unused].tel, &tmpid);
  67.             cur = head;
  68.             while(cur && cur->id != tmpid){
  69.                 cur = cur->next;
  70.             }
  71.             linkedlist[unused].next = cur->next;
  72.             cur->next = linkedlist + unused;
  73.             if(!linkedlist[unused].next){
  74.                 tail = linkedlist + unused;
  75.             }
  76.             unused++;
  77.             break;
  78.         case 3:
  79.             scanf("%d", &tmpid);
  80.             if(head->id == tmpid){
  81.                 head = head->next;
  82.             }
  83.             else{
  84.                 node *cur = head;
  85.                 while(cur->next && cur->next->id != tmpid){
  86.                     cur = cur->next;
  87.                 }
  88.                 cur->next = cur->next->next;
  89.                 if(!cur->next){
  90.                     tail = cur;
  91.                 }
  92.             }
  93.             break;
  94.         default:
  95.             break;
  96.         }
  97.     }
  98.     node *pos = head;
  99.     while(pos){
  100.         printf("%s %d %s %lld\n", pos->name, pos->id, pos->gender, pos->tel);
  101.         pos = pos->next;
  102.     }
  103. #ifdef _DEBUG
  104.     fp = freopen("CON", "r", stdin);
  105.     //fp2 = freopen("CON", "w", stdout);
  106.     system("pause");
  107. #endif // _DEBUG
  108.     return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement