Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <locale>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "RU");
- char str[50];
- int i = 0, prob = 0, words = 1;
- cout << "Введите текст: ";
- gets_s(str);
- for (int i = 0;str[i] != 0;i++) {
- if (str[i] == ' ') words++;
- }
- int *ind = new int[words],g=0;
- while (str[i] != '\0')
- {
- while (str[i] == ' ')
- {
- ind[g] = i;
- g++;
- i++;
- }
- while (str[i] != '\0' && str[i] != ' ')
- {
- i++;
- }
- }
- str[i] = ' ';
- str[i + 1] = '\0';
- ind[g] = i;
- int min, max, ind1min, ind2min, ind1max, ind2max;
- ind1min = 0;
- ind1max = 0;
- ind2min = ind[0];
- ind2max = ind[0];
- min = ind2min - ind1min-1;
- max = ind2max - ind1max;
- for (int i = 1;i < words-1;i++) {
- if (min > ind[i + 1] - (ind[i]+ 1)) {
- ind1min = ind[i]+1;
- ind2min = ind[i+1];
- min = ind2min - ind1min;
- }
- if (max < ind[i + 1] - (ind[i] + 1)) {
- ind1max = ind[i] + 1;
- ind2max = ind[i + 1];
- max = ind2max - ind1max;
- }
- }
- cout << "минимальное: ";
- for (int i = ind1min;i < ind2min;i++) {
- cout << str[i];
- }
- cout << endl;
- cout<<"Максимальное: ";
- for (int i = ind1max;i < ind2max;i++) {
- cout << str[i];
- }
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement