Advertisement
a53

virus1

a53
Jun 16th, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstring>
  3. #define LGMAX 202
  4. #define CMAX 100002
  5. using namespace std;
  6. ifstream fin("virus.in");
  7. ofstream fout("virus.out");
  8. int n, rez, P, lgv, lgc;
  9. int nr[CMAX];
  10. char v[LGMAX], c[LGMAX], cmaxim[LGMAX];
  11. void mutatie (int & poz, int& litera);
  12. void codul(int x,char s[LGMAX]);
  13. int main()
  14. {int i, litera, poz, maxim;
  15. fin>>P>>v>>n;
  16. lgv=strlen(v);
  17. for (i=1; i<=n; i++)
  18. {fin>>c; lgc=strlen(c);
  19. mutatie(poz, litera);
  20. if (poz!=-1)
  21. {
  22. rez++;
  23. nr[poz*100+litera]++;
  24. }
  25. }
  26. if (P==1)
  27. fout<<rez<<'\n';
  28. else
  29. {
  30. maxim=0;
  31. for (i=0; i<CMAX; i++)
  32. if (nr[i]>maxim)
  33. maxim=nr[i];
  34. cmaxim[0]='z'+1;
  35. for (i=0; i<CMAX; i++)
  36. if (nr[i]==maxim)
  37. {
  38. codul(i,c);
  39. if (strcmp(c,cmaxim)<0) strcpy(cmaxim,c);
  40. }
  41. fout<<cmaxim<<'\n';
  42. }
  43. return 0;
  44. }
  45.  
  46. void mutatie (int & poz, int &litera)
  47. {int i;
  48. poz=-1;
  49. if (lgv!=lgc) return;
  50. for (i=0; i<lgv; i++)
  51. if (v[i]!=c[i])
  52. if (poz==-1) poz=i;
  53. else {poz=-1; return; }
  54. if (poz==-1) return;
  55. if (c[poz]>='A' && c[poz]<='Z') litera=c[poz]-'A';
  56. else litera=c[poz]-'a'+26;
  57. }
  58.  
  59. void codul(int x,char s[LGMAX])
  60. {int poz; char litera;
  61. strcpy(s,v);
  62. poz=x/100;
  63. if (x%100<26) litera='A'+x%100;
  64. else litera='a'+(x%100-26);
  65. s[poz]=litera;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement