Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct node {
- int tstart;
- char *num;
- struct node *next;
- };
- struct node *start = NULL;
- void del(int tim) { //usuwam z przodu, print z wymogow zadania
- struct node *t;
- int tstart;
- char *num=malloc(60*sizeof(char));
- num = start->num;
- tstart=start->tstart;
- t = start->next;
- free(start);
- start = t;
- printf("%s %d\n", num, tim-tstart);
- }
- void insert(int tstart, char *num) { //dodaje na koncu
- struct node *t, *temp;
- t = (struct node*)malloc(sizeof(struct node));
- t->tstart = tstart;
- t->num=num;
- if (start == NULL) {
- start = t;
- start->next = NULL;
- return;
- }
- temp = start;
- while (temp->next != NULL)
- temp = temp->next;
- temp->next = t;
- t->next = NULL;
- }
- void aresolve(char *input)
- {
- int tstart;
- char *num=malloc(60*sizeof(char));
- sscanf(input,"a %d %s", &tstart,num);
- insert(tstart,num); //dodaje node z wartosciami co trzeba
- }
- void rresolve(char *input)
- {
- int tim=0;
- sscanf(input,"r %d",&tim);
- del(tim); //wyrzucam element na poczatku kolejki, printuje dane
- }
- void dowork(char *input) //wywoluje do kazdego inputa
- {
- if(input[0]=='a')
- {
- aresolve(input);
- }
- else if(input[0]=='r')
- {
- rresolve(input);
- }
- return;
- }
- int main()
- {
- int n;
- scanf("%d",&n);
- for(int i=0; i<n+1; i++)
- {
- char *input=malloc(60*sizeof(char));
- fgets(input,59,stdin);
- dowork(input);
- free(input);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement