Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- int cnt[26];
- int main(void) {
- int n, c, k = 1, m = 1, i = 0;
- scanf("%d %d", &n, &c);
- c++;
- char forca[n][c], wordInt[n][c], wordT[c], wordBackup[c];
- for (int b = 0; b < n; b++) {
- scanf(" %s", forca[b]);
- }
- for (int j = 0; j < n; j++) {
- for (int t = 0; t < c; t++) {
- wordInt[j][t] = forca[j][t];
- }
- }
- while (i < n) {
- for(int j = 0; j < 26; j++) {
- cnt[j] = 0;
- }
- if ((n - (i + 1)) >= m) {
- for (int p = i + 1, t = i; p < n; p++) {
- for (int j = 0; j < c; j++) {
- if (wordInt[t][j] != forca[p][j]) {
- if (wordInt[t][j] != '*' && forca[p][j] != '*') {
- j = c;
- }
- }
- if ((j + 1) == c) {
- for (int mb = 0; mb < c; mb++) {
- if (wordInt[t][mb] == '*') {
- if(forca[p][mb] == '*') {
- for(int a = 0; a < 26; a++) {
- cnt[a]++;
- }
- } else {
- cnt[forca[p][mb] - 'a']++;
- }
- }
- }
- }
- }
- }
- }
- int mx = 0, id = 0;
- for(int j = 0; j < 26; j++) {
- if(cnt[j] > mx) {
- mx = cnt[j];
- id = j;
- }
- }
- for(int j = 0; j < c; j++) {
- if(wordInt[i][j] == '*') {
- wordInt[i][j] = (char)('a' + id);
- break;
- }
- }
- k = mx + 1;
- if (k >= m) {
- int w = strncmp(wordT, wordInt[i], c);
- if (w > 0 && k == m && k > 1) {
- strncpy(wordT, wordInt[i], c);
- }
- else if (k > m || i == 0) {
- strncpy(wordT, wordInt[i], c);
- m = k;
- }
- }
- if (m == n) {
- break;
- }
- k = 1;
- i++;
- }
- for (int i = 0; i < c; i++) {
- if (wordT[i] == '*') {
- wordT[i] = 'a';
- }
- }
- printf("%s ", wordT);
- printf("%d\n", m);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement