Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: 曹北健
- Result: AC Submission_id: 4432711
- Created at: Fri May 13 2022 19:31:52 GMT+0800 (China Standard Time)
- Problem_id: 5758 Time: 719 Memory: 2816
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
- #include <ctype.h>
- #pragma warning(disable:4996)
- typedef long long s64, LL;
- typedef unsigned long long u64, ULL;
- typedef struct node{
- char name[52];
- char gender[8];
- int id;
- LL tel;
- struct node *next;
- }node;
- node linkedlist[114514] = { 0 }, *head, *tail;
- int unused = 0;
- int main(){
- #ifdef _DEBUG
- FILE *fp = freopen("../../../input.txt", "r", stdin);
- //FILE *fp2 = freopen("../../../output.txt", "w", stdout);
- #endif // _DEBUG
- int n, m, op, tmpid;
- char tmpname[52] = { 0 }, tmpgender[8] = { 0 };
- LL tmptel;
- node *cur;
- scanf("%d%d", &n, &m);
- for(unused = 0; unused < n; unused++){
- scanf("%s%d%s%lld", linkedlist[unused].name, &linkedlist[unused].id, linkedlist[unused].gender, &linkedlist[unused].tel);
- linkedlist[unused].next = linkedlist + unused + 1;
- }
- linkedlist[n - 1].next = 0;
- head = linkedlist;
- tail = linkedlist + n - 1;
- while(m--){
- scanf("%d", &op);
- switch(op){
- case 1:
- //scanf("%s%d%s%lld", tmpname, &tmpid, tmpgender, &tmptel);
- //addtail(tmpname, tmpgender, tmpid, tmptel);
- scanf("%s%d%s%lld", linkedlist[unused].name, &linkedlist[unused].id, linkedlist[unused].gender, &linkedlist[unused].tel);
- //linkedlist[unused].next = 0;
- tail->next = linkedlist + unused;
- tail = tail->next;
- unused++;
- break;
- case 2:
- scanf("%d%lld", &tmpid, &tmptel);
- //updatetel(tmpid, tmptel);
- cur = head;
- while(cur && cur->id != tmpid){
- cur = cur->next;
- }
- cur->tel = tmptel;
- break;
- case 4:
- //scanf("%s%d%s%lld%d", tmpname, &tmpid, tmpgender, &tmptel, &tmpid2);
- //addafter(tmpname, tmpgender, tmpid, tmptel, tmpid2);
- scanf("%s%d%s%lld%d", linkedlist[unused].name, &linkedlist[unused].id, linkedlist[unused].gender, &linkedlist[unused].tel, &tmpid);
- cur = head;
- while(cur && cur->id != tmpid){
- cur = cur->next;
- }
- linkedlist[unused].next = cur->next;
- cur->next = linkedlist + unused;
- if(!linkedlist[unused].next){
- tail = linkedlist + unused;
- }
- unused++;
- break;
- case 3:
- scanf("%d", &tmpid);
- if(head->id == tmpid){
- head = head->next;
- }
- else{
- node *cur = head;
- while(cur->next && cur->next->id != tmpid){
- cur = cur->next;
- }
- cur->next = cur->next->next;
- if(!cur->next){
- tail = cur;
- }
- }
- break;
- default:
- break;
- }
- }
- node *pos = head;
- while(pos){
- printf("%s %d %s %lld\n", pos->name, pos->id, pos->gender, pos->tel);
- pos = pos->next;
- }
- #ifdef _DEBUG
- fp = freopen("CON", "r", stdin);
- //fp2 = freopen("CON", "w", stdout);
- system("pause");
- #endif // _DEBUG
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement