Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- void append(char**stack, int top, char* action)
- {
- for (int i=0; i<25; i++)
- {
- stack[top][i]=action[i];
- }
- }
- int convert(char* string,int n)
- {
- n--;
- int num = 0;
- int modifier = 1;
- while (n>=0)
- {
- int a = string[n]-'0';
- a *= modifier;
- modifier *= 10;
- num += a;
- n--;
- }
- return num;
- }
- void fremove(char**stack, char* action,int beg)
- {
- char time_1[5];
- int i=0;
- //printf("%s",stack[0]);
- while (stack[beg][i+2]!=' '&& i<5)
- {
- time_1[i]=stack[beg][i+2];
- i++;
- }
- int t_1=convert(time_1,i);
- char number[15];
- for (int i=0; i<15; i++)
- number[i]=' ';
- i++;
- int j=0;
- while (stack[beg][i+2]!=' '&& i+2<25)
- {
- number[j]=stack[beg][i+2];
- i++;
- j++;
- }
- char time_2[5];
- i=0;
- while (isdigit(action[i+2])&&i<5&& i+2<strlen(action))
- {
- time_2[i]=action[i+2];
- i++;
- }
- int t_2=convert(time_2,i);
- i=0;
- int c=t_2-t_1;
- printf("%s %d",number,c);
- }
- void print(char ** stack, int top)
- {
- printf("\n");
- for (int i=0; i<top; i++)
- {
- printf(" %s ",stack[i]);
- }
- }
- int main()
- {
- int n;
- scanf("%d",&n);
- char action[25];
- char temp;
- char * data=malloc(sizeof(char)*26*n);
- char ** stack=malloc(n*sizeof(char*));
- int top=0;
- int beg=0;
- for (int i=0; i<n ; i++)
- {
- stack[i]=data+i*25;
- }
- for (int i=0; i<n; i++)
- {
- scanf("%c",&temp);
- scanf("%[^\n]",action);
- if (action[0]=='a')
- {
- append(stack,top,action);
- top++;
- }
- else if (action[0]=='r')
- {
- fremove(stack,action,beg);
- beg++;
- }
- }
- free(data);
- free(stack);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement