Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.28 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4.  
  5.  
  6. struct key {
  7. char *word;
  8. int count;
  9. int score;
  10. } mas[] = {
  11. "auto", 0,1,
  12. "break", 0,1,
  13. "case", 0,1,
  14. "char", 0,1,
  15. "const", 0,1,
  16. "continue", 0,1,
  17. "default", 0,1,
  18. "unsigned", 0,1,
  19. "void", 0,1,
  20. "volatile", 0,1,
  21. "while", 0,1,
  22. };
  23.  
  24. struct key arr[1000];
  25.  
  26.  
  27. int gethash(char *slovo, int line);
  28.  
  29. int main()
  30. {
  31.  
  32. printf("Список ключевых слов ");
  33.  
  34.     int x=0;
  35.     int hash[10];
  36.     int j;
  37.     int help;
  38.     int t;  
  39.     int temp;
  40.        
  41.      for (int z=0; z<=1000; z++)
  42.    {
  43.       arr[z].count=0;
  44.       arr[z].score=0;
  45.          
  46.  
  47.     }
  48.  
  49.     for(x=0; x<=10; x++)
  50.     {
  51.         hash[x]=0;
  52.         j=0;
  53.        
  54.         t=strlen(mas[x].word);
  55.        
  56.         while(t > 0)
  57.         {
  58.             help=mas[x].word[j];
  59.            
  60.             hash[x]= hash[x] + help;
  61.             j++;
  62.             t--;
  63.         }
  64.        
  65.         temp=hash[x];
  66.  
  67.       arr[temp].score=1;
  68.       arr[temp].word=mas[x].word;
  69.        
  70. printf("\n %s \n", mas[x].word);
  71.      }
  72.    
  73.    
  74.    
  75.      
  76.  
  77. int line;
  78. int p;
  79. char c;
  80. char *ukaz[100];
  81. char slova[1000][1000];
  82. int i1,j1=0;
  83. int k=0;
  84. int q=0;
  85. char name[100];
  86.  
  87.  
  88.  
  89.  
  90. printf("Введите название файла  ");
  91.     scanf("%s",name);
  92.  
  93.     FILE *f;
  94.     if ((f=fopen(name, "r"))==0)
  95.     {
  96.         printf("Неверное имя файла");
  97.         return 0;
  98.     }
  99.    
  100.  
  101.  
  102. while ((c=fgetc(f))!=EOF)
  103. {
  104. if (isspace(c)!=0) 
  105.     {
  106.     ukaz[j1]=slova[j1];
  107.     j1++;  
  108.     i1=0;
  109.     }
  110.    
  111. else{      
  112.     slova[j1][i1]=c;
  113.     i1++;
  114.     }
  115. }
  116.        
  117.  
  118.    
  119. fclose(f);
  120.  
  121.  
  122.  
  123. for (q=0; q<j1; q++)
  124.   {
  125.         line=strlen(ukaz[q]);
  126.           p=gethash(ukaz[q],line);
  127.  
  128.          if (p<=1000 && arr[p].score!=0)
  129.          {
  130.            arr[p].count++;
  131.          }
  132.   }
  133.  
  134.  
  135. for (int z=400; z<=1000; z++)
  136.      {
  137.       if (arr[z].score!=0)
  138.         {
  139.         printf("Ключевое слово %s встретилось \t",arr[z].word);
  140.              
  141.         printf("%d раз(а)\n",arr[z].count);
  142.         }
  143.        
  144.       }
  145.    
  146.  
  147.  }  
  148.  
  149.  
  150.  
  151. int gethash(char *slovo, int line)
  152. {
  153.    
  154.     int hash=0;
  155.     int j=0;
  156.     int help;
  157.    
  158.        
  159.         while(line>0)
  160.         {
  161.             help=slovo[j];
  162.            
  163.             hash= hash+ help;
  164.             j++;
  165.             line--;
  166.         }
  167.     return hash;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement