Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <locale>
  3. using namespace std;
  4.  
  5. int main() {
  6. setlocale(LC_ALL, "RU");
  7. char str[50];
  8. int i = 0, prob = 0, words = 1;
  9. cout << "Введите текст: ";
  10. gets_s(str);
  11. for (int i = 0;str[i] != 0;i++) {
  12. if (str[i] == ' ') words++;
  13. }
  14. int *ind = new int[words],g=0;
  15. while (str[i] != '\0')
  16. {
  17.  
  18. while (str[i] == ' ')
  19. {
  20. ind[g] = i;
  21. g++;
  22. i++;
  23. }
  24. while (str[i] != '\0' && str[i] != ' ')
  25. {
  26.  
  27. i++;
  28. }
  29. }
  30. str[i] = ' ';
  31. str[i + 1] = '\0';
  32. ind[g] = i;
  33. int min, max, ind1min, ind2min, ind1max, ind2max;
  34. ind1min = 0;
  35. ind1max = 0;
  36. ind2min = ind[0];
  37. ind2max = ind[0];
  38. min = ind2min - ind1min-1;
  39. max = ind2max - ind1max;
  40. for (int i = 1;i < words-1;i++) {
  41. if (min > ind[i + 1] - (ind[i]+ 1)) {
  42. ind1min = ind[i]+1;
  43. ind2min = ind[i+1];
  44. min = ind2min - ind1min;
  45. }
  46. if (max < ind[i + 1] - (ind[i] + 1)) {
  47. ind1max = ind[i] + 1;
  48. ind2max = ind[i + 1];
  49. max = ind2max - ind1max;
  50. }
  51. }
  52. cout << "минимальное: ";
  53. for (int i = ind1min;i < ind2min;i++) {
  54. cout << str[i];
  55. }
  56. cout << endl;
  57. cout<<"Максимальное: ";
  58. for (int i = ind1max;i < ind2max;i++) {
  59. cout << str[i];
  60. }
  61. cout << endl;
  62. system("pause");
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement