Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. void append(char**stack, int top, char* action)
  6. {
  7. for (int i=0; i<25; i++)
  8. {
  9. stack[top][i]=action[i];
  10. }
  11.  
  12.  
  13.  
  14. }
  15. int convert(char* string,int n)
  16. {
  17. n--;
  18. int num = 0;
  19. int modifier = 1;
  20. while (n>=0)
  21. {
  22. int a = string[n]-'0';
  23.  
  24. a *= modifier;
  25. modifier *= 10;
  26. num += a;
  27. n--;
  28. }
  29. return num;
  30. }
  31. void fremove(char**stack, char* action,int beg)
  32. {
  33.  
  34. char time_1[5];
  35. int i=0;
  36. //printf("%s",stack[0]);
  37. while (stack[beg][i+2]!=' '&& i<5)
  38. {
  39.  
  40. time_1[i]=stack[beg][i+2];
  41. i++;
  42. }
  43.  
  44. int t_1=convert(time_1,i);
  45.  
  46.  
  47. char number[15];
  48. for (int i=0; i<15; i++)
  49. number[i]=' ';
  50.  
  51. i++;
  52. int j=0;
  53. while (stack[beg][i+2]!=' '&& i+2<25)
  54. {
  55. number[j]=stack[beg][i+2];
  56. i++;
  57. j++;
  58. }
  59.  
  60.  
  61. char time_2[5];
  62. i=0;
  63. while (isdigit(action[i+2])&&i<5&& i+2<strlen(action))
  64. {
  65. time_2[i]=action[i+2];
  66. i++;
  67. }
  68. int t_2=convert(time_2,i);
  69. i=0;
  70.  
  71. int c=t_2-t_1;
  72. printf("%s %d",number,c);
  73.  
  74.  
  75.  
  76.  
  77. }
  78. void print(char ** stack, int top)
  79. {
  80. printf("\n");
  81. for (int i=0; i<top; i++)
  82. {
  83. printf(" %s ",stack[i]);
  84. }
  85. }
  86. int main()
  87. {
  88. int n;
  89. scanf("%d",&n);
  90. char action[25];
  91. char temp;
  92. char * data=malloc(sizeof(char)*26*n);
  93. char ** stack=malloc(n*sizeof(char*));
  94. int top=0;
  95. int beg=0;
  96.  
  97. for (int i=0; i<n ; i++)
  98. {
  99. stack[i]=data+i*25;
  100. }
  101.  
  102. for (int i=0; i<n; i++)
  103. {
  104.  
  105. scanf("%c",&temp);
  106. scanf("%[^\n]",action);
  107.  
  108. if (action[0]=='a')
  109. {
  110.  
  111. append(stack,top,action);
  112. top++;
  113.  
  114.  
  115. }
  116. else if (action[0]=='r')
  117. {
  118.  
  119.  
  120. fremove(stack,action,beg);
  121. beg++;
  122.  
  123. }
  124. }
  125.  
  126.  
  127. free(data);
  128. free(stack);
  129.  
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement