Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. typedef struct Sentence{
  5.     int size;
  6.     int histo[26];
  7.     }Sentence;
  8.  
  9.  
  10. int main(int argc, char *argv[]) {
  11.     char c;
  12.     int count, n, m, i, j, k, *frequencies, *frequencies2;
  13.     Sentence* letterCount;
  14.     Sentence* letterCount2;
  15.     scanf("%d", &n);
  16.     letterCount = calloc(n, sizeof(Sentence));
  17.     frequencies = calloc(n, sizeof(int));
  18.     for(i=0; i < n; i++){
  19.         count = 0;
  20.         while((c = getchar()) && (c != '.')){
  21.             if(c != ' '){
  22.                 if (c >= 'a' && c <= 'z' ) {
  23.                 letterCount[i].histo[c -'a']++;
  24.                 count++;
  25.                 letterCount[i].size = count; // size of the array
  26.         }  
  27.     }
  28. }  
  29.     frequencies[i] = letterCount[i].size;  
  30.  
  31. }
  32.  
  33.  
  34.     scanf("%d", &m);
  35.     frequencies2 = calloc(m, sizeof(int));
  36.     letterCount2 = calloc(n, sizeof(Sentence));
  37.  
  38.     for(i=0; i < m; i++){
  39.         count = 0;
  40.         while((c = getchar()) && (c != '.')){
  41.         if(c != ' '){
  42.             if (c >= 'a' && c <= 'z' ) {
  43.             letterCount2[i].histo[c -'a']++;
  44.             count++;
  45.             letterCount2[i].size = count; // size of the array
  46.         }
  47.     }
  48. }
  49.     frequencies2[i] = letterCount2[i].size;
  50. }
  51.    
  52.     for(i=0; i<m; i++){
  53.         for(j=0; j<n; j++){
  54.             if (frequencies2[i] == frequencies[j]){
  55.                 k=0;
  56.                 while((letterCount2[i].histo[k] == letterCount[j].histo[k]) && k<27){
  57.                     k++;   
  58.                 }
  59.                 if((k = 27)){
  60.                 printf("%d ", j+1);
  61.             }
  62.         }
  63.     }
  64.     printf("\n");
  65. }
  66.  
  67.  
  68.  
  69.  
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement