Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. struct word {char *str;
  6. int count;
  7. struct word *next;
  8. }*first=NULL,kol;
  9.  
  10. int main()
  11. {
  12. void output(void);
  13. void copy_next(int ,char []);
  14. int i=0;
  15.  
  16. char buf[2048];
  17.  
  18. struct word *q;
  19.  
  20. kol.count=0;
  21.  
  22. while((buf[i]=getchar())!=EOF)
  23. {
  24. if((buf[i]<='z' && buf[i]>='a')||(buf[i]>='A' && buf[i]<='Z'))
  25. {
  26. i++;
  27. }
  28. if(((buf[i]==' ')||(buf[i]=='\t')||(buf[i]=='\n'))&&(i!=0))
  29. {
  30. buf[i]='\0';
  31. i=0;
  32. copy_next(i,buf);
  33. }
  34. }
  35. printf("\n");
  36.  
  37. while(first)
  38. {
  39. output();
  40. }
  41. }
  42.  
  43.  
  44. void output(void)
  45. {
  46. struct word *q;
  47. if(kol.count==0)
  48. {
  49. printf("%s ",first->str);
  50. printf("%d\n",kol.count);
  51. }
  52. q=first;
  53. first=first->next;
  54. free(q->str);
  55. free(q);
  56. }
  57.  
  58.  
  59. void copy_next(int i,char buf[])
  60. {
  61. char* r;
  62. struct word *q;
  63. struct word *r2;
  64. struct word *first1;
  65. struct word kol2;
  66. int k=0;
  67.  
  68. first1=first;
  69.  
  70. r=(char*)malloc(i);
  71. if(r==NULL)
  72. {
  73. exit(1);
  74. }
  75.  
  76.  
  77. if((r2=(struct word *)malloc(sizeof(struct word)))==NULL)
  78. {
  79. exit (1);
  80. }
  81.  
  82. strcpy(r,buf);
  83.  
  84. while(first1)
  85. {
  86. if(r2->str==r)
  87. {
  88. kol2.count=k+1;
  89. free(r);
  90. }
  91. q=first1;
  92. first1=first1->next;
  93. }
  94.  
  95.  
  96. r2->str=r;
  97. q=first;
  98. first=r2;
  99. r2->next=q;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement