Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- typedef struct callcenter{
- char *nr;
- int time;
- }callcenter;
- typedef struct queue{
- int first, last, size;
- callcenter *arr;
- }queue;
- queue *create_queue(int size) {
- queue *q = malloc(sizeof(queue));
- q -> first = 0;
- q -> last = 0;
- q -> size = size;
- q -> arr = malloc(size * sizeof(callcenter));
- return q;
- }
- void del_queue(queue *q) {
- free(q -> arr);
- free(q);
- }
- callcenter get(queue *q) {
- if(q -> first + 1 < q -> size){
- q -> first++;
- return q -> arr[q -> first];
- }else {
- q -> first = 0;
- return q -> arr[q -> first];
- }
- }
- void put(char* nr, int time, queue *q) {
- if(q -> last + 1 < q -> size) {
- q -> last++;
- q -> arr[q -> last].nr = nr;
- q -> arr[q -> last].time = time;
- } else {
- q -> last = 0;
- q -> arr[q -> last].nr = nr;
- q -> arr[q -> last].time = time;
- }
- }
- bool empty(queue *q){
- return q -> first == q -> last;
- }
- int main() {
- int n;
- scanf("%d", &n);
- queue *que = create_queue(n);
- queue *res = create_queue(n);
- for(int i = 0; i < n; i++) {
- char type;
- int time;
- scanf(" %c %d", &type, &time);
- printf("char: %c time: %d", type, time);
- if(type == 'a'){
- char nr[16];
- scanf(" %s", &nr);
- printf(" nr : %s", nr);
- put(nr, time, que);
- }
- else if(type == 'r'){
- callcenter mem = get(que);
- int t = time - mem.time;
- put(mem.nr, t, res);
- }
- }
- while(!empty(res)){
- callcenter ans = get(res);
- printf("%d %s \n", ans.time, ans.nr);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement