Ах ты ж мелкий, сам КБО написать не можешь?) - это приговор.
Объяснение:
#include <bits/stdc++.h>
using namespace std;
int cnt[30], kol;
string s;
bool check (int mid) {
int x[30]{}, y = 0;
for (int i = 0; i < mid; i++) {
x[s[i] - 'a' + 1]++;
if (x[s[i] - 'a' + 1] == 1)
y++;
}
int l, r = mid - 1;
for (l = 0; r < s.size();) {
if (y == kol)
return true;
if (x[s[l] - 'a' + 1] == 1)
y--;
x[s[l] - 'a' + 1]--;
l++;
r++;
if (x[s[r] - 'a' + 1] == 0)
y++;
x[s[r] - 'a' + 1]++;
}
return false;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> s;
for (auto it : s)
cnt[it - 'a' + 1]++;
for (int i = 1; i <= 26; i++) {
if (cnt[i] > 0)
kol++;
}
int l = 0, r = s.size();
while (r - l > 1) {
int mid = l + (r - l) / 2;
if (check (mid))
r = mid;
else
l = mid;
}
cout << r;
}
#define use_CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <cstring>
using namespace std;
int main() {
setlocale(LC_ALL, "Russian");
const int N = 81;
const int N2 = 81;
int numbers[N];
int count = 0;
int count2 = 0;
string words[N];
string kwords[N2];
char the_string[N], * p;
char* next_token = nullptr;
int i = 0;
for (int k = 0; k < N; k++) {
numbers[k] = 0;
}
cout << "Введите строку:";
cin.getline(the_string, N);
p = strtok_s(the_string, " ", &next_token);
while (p != nullptr) {
words[i] = p;
i++;
p = strtok_s(nullptr, " ", &next_token);
count++;
}
cout << endl;
char the_string2[N2], * p2;
char* next_token2 = nullptr;
cout << "Введите нужные слова:";
cin.getline(the_string2, N2);
int j = 0;
p2 = strtok_s(the_string2, " ", &next_token2);
while (p2 != nullptr) {
kwords[j] = p2;
j++;
p2 = strtok_s(nullptr, " ", &next_token2);
count2++;
}
cout << endl;
for (int i = 0; i < count; i++) {
for (int j = 0; j < count2; j++) {
if (words[i] == kwords[j]) {
numbers[j] = numbers[j] + 1;
break;
}
}
}
int t; string d;
for (int j = 0; j < count2; j++) {
for (int i = 0; i < count2; i++) {
if (numbers[i] < numbers[i + 1]) {
t = numbers[i + 1];
numbers[i + 1] = numbers[i];
numbers[i] = t;
d = kwords[i + 1];
kwords[i + 1] = kwords[i];
kwords[i] = d;
}
}
}
cout << endl;
for (int i = 0; i < count2; i++) {
cout << kwords[i] << " ";
}
return 0;
}