Advertisement
Guest User

Untitled

a guest
May 24th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. struct stack
  5. {
  6. struct stack *prev;
  7. struct stack *next;
  8. int l,r;//позиции скобок
  9. }*head;
  10. void push(struct stack*j)
  11. {
  12. if(head==0)
  13. head = j;
  14. else {
  15. head->next = j;
  16. j->prev=head;
  17. head = j;
  18. }
  19. }
  20. void pop()
  21. {
  22. if(head!=0)
  23. {
  24. head=head->prev;
  25. free(head->next);
  26. head->next = 0;
  27. }
  28. else
  29. return;
  30. }
  31. void vivod()
  32. {
  33. struct stack *i;
  34. for(i=head;i!=0;i=i->prev)
  35. printf("(%d,%d)",i->l,i->r);
  36. }
  37. main(void)
  38. {
  39. head = 0;
  40. char m[60];
  41. int *x,*y;
  42. int i=0;
  43. int g;
  44. int k,q,w;
  45. FILE *f;
  46. f = fopen("text.txt","r");
  47. fscanf(f,"%s",m);
  48. g = strlen(m);
  49. for(i=0;i<g;i++)
  50. if(m[i]='(')
  51. k++;
  52. x = (int*)(malloc(sizeof(int)*(k)));
  53. y = (int*)(malloc(sizeof(int)*(k)));
  54. for(i=0,q=0,w=0;i<g;i++)
  55. {if(m[i]=='(')
  56. x[q]=i, q++;
  57. if(m[g - i - 1]==')')
  58. y[w]= g - i - 1,w++;}
  59. for(i=0;i<k;i++)
  60. {
  61. struct stack*name = (struct stack*)(malloc(sizeof(struct stack)));
  62. name->l=x[i];
  63. name->r=y[i];
  64. name->next = 0;
  65. name->prev=0;
  66. push(name);
  67.  
  68. }
  69. vivod();
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement