wojiaocbj

Untitled

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