Advertisement
cosenza987

Untitled

May 1st, 2023
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4.  
  5. int cnt[26];
  6.  
  7. int main(void) {
  8.     int n, c, k = 1, m = 1, i = 0;
  9.     scanf("%d %d", &n, &c);
  10.     c++;
  11.     char forca[n][c], wordInt[n][c], wordT[c], wordBackup[c];
  12.  
  13.     for (int b = 0; b < n; b++) {
  14.         scanf(" %s", forca[b]);
  15.     }
  16.  
  17.     for (int j = 0; j < n; j++) {
  18.         for (int t = 0; t < c; t++) {
  19.             wordInt[j][t] = forca[j][t];
  20.         }
  21.     }
  22.  
  23.     while (i < n) {
  24.         for(int j = 0; j < 26; j++) {
  25.             cnt[j] = 0;
  26.         }
  27.         if ((n - (i + 1)) >= m) {
  28.             for (int p = i + 1, t = i; p < n; p++) {
  29.                 for (int j = 0; j < c; j++) {
  30.                     if (wordInt[t][j] != forca[p][j]) {
  31.                         if (wordInt[t][j] != '*' && forca[p][j] != '*') {
  32.                             j = c;
  33.                         }
  34.                     }
  35.                     if ((j + 1) == c) {
  36.                         for (int mb = 0; mb < c; mb++) {
  37.                             if (wordInt[t][mb] == '*') {
  38.                                 if(forca[p][mb] == '*') {
  39.                                     for(int a = 0; a < 26; a++) {
  40.                                         cnt[a]++;
  41.                                     }
  42.                                 } else {
  43.                                     cnt[forca[p][mb] - 'a']++;
  44.                                 }
  45.                             }
  46.                         }
  47.                     }
  48.                 }
  49.             }
  50.         }
  51.         int mx = 0, id = 0;
  52.         for(int j = 0; j < 26; j++) {
  53.             if(cnt[j] > mx) {
  54.                 mx = cnt[j];
  55.                 id = j;
  56.             }
  57.         }
  58.         for(int j = 0; j < c; j++) {
  59.             if(wordInt[i][j] == '*') {
  60.                 wordInt[i][j] = (char)('a' + id);
  61.                 break;
  62.             }
  63.         }
  64.         k = mx + 1;
  65.         if (k >= m) {
  66.             int w = strncmp(wordT, wordInt[i], c);
  67.             if (w > 0 && k == m && k > 1) {
  68.                 strncpy(wordT, wordInt[i], c);
  69.             }
  70.             else if (k > m || i == 0) {
  71.                 strncpy(wordT, wordInt[i], c);
  72.                 m = k;
  73.             }
  74.         }
  75.  
  76.         if (m == n) {
  77.             break;
  78.         }
  79.  
  80.         k = 1;
  81.         i++;
  82.     }
  83.  
  84.     for (int i = 0; i < c; i++) {
  85.         if (wordT[i] == '*') {
  86.             wordT[i] = 'a';
  87.         }
  88.     }
  89.     printf("%s ", wordT);
  90.     printf("%d\n", m);
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement