#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;
}
Поделитесь своими знаниями, ответьте на вопрос:
Определите, количество чисел k, для которых следующая программа выведет такой же результат, что и для k = 10? паскаль var k, i : longint; function f(n: longint): longint; begin f: = n * n * n; end; begin readln(k); i : = 1; while f(i) < k do i : = i + 1; if f(i)-k < = k-f(i-1) then writeln(i) else writeln(i-1); end.
var
k, rk, n: longint;
function f(n: longint): longint;
begin
f := n * n * n;
end;
function calc(k: longint): longint;
var
i: longint;
begin
i := 1;
while f(i) < k do
i := i + 1;
if f(i) - k <= k - f(i - 1) then
calc := i
else calc := i - 1;
end;
begin
rk := calc(10);
n := 0;
for k := 1 to 1000 do
if calc(k) = rk then
begin
writeln('calc(', k, ') = ', calc(k));
n := n + 1;
end;
writeln(n);
end.
вывод
calc(5) = 2
calc(6) = 2
calc(7) = 2
calc(8) = 2
calc(9) = 2
calc(10) = 2
calc(11) = 2
calc(12) = 2
calc(13) = 2
calc(14) = 2
calc(15) = 2
calc(16) = 2
calc(17) = 2
13