Advertisement
a53

criptografie

a53
May 8th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5. long long sol;
  6. char s[100010];
  7. int c, k, n, i, p, maxim;
  8. char ch;
  9. char smaxim[27];
  10. int f[26];
  11. int main () {
  12. ifstream fin ("criptografie.in");
  13. ofstream fout("criptografie.out");
  14.  
  15. fin>>c;
  16. fin>>k>>n;
  17. for (i=1;i<=n;i++)
  18. fin>>s[i];
  19.  
  20. p = 1;
  21. strcpy(smaxim, "zz");
  22. for (i=1;i<=n;i++) {
  23. ch = s[i]-'a';
  24. f[ ch ] ++;
  25. while ( f[ch] > k ) {
  26. f[ s[p]-'a' ]--;
  27. p++;
  28. }
  29. if (c == 1)
  30. sol += i-p+1;
  31. else {
  32. if (i-p+1 > maxim) {
  33. maxim = i-p+1;
  34. strncpy(smaxim, s+p, maxim);
  35. } else
  36. if (i-p+1 == maxim)
  37. if (strncmp(smaxim, s+p, maxim) > 0)
  38. strncpy(smaxim, s+p, maxim);
  39.  
  40. }
  41. }
  42. if (c == 1)
  43. fout<<sol;
  44. else {
  45. smaxim[maxim] = 0;
  46. fout<<smaxim;
  47. }
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement