evcamels

lr-5

Dec 19th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // lr-2
  4. //
  5. // Created by Nikita Korvyakov on 19.12.2020.
  6. // Copyright © 2020 Nikita Korvyakov. All rights reserved.
  7. //
  8.  
  9. #include<iostream>
  10. #include<string>
  11. #include<sstream>
  12.  
  13. using namespace std;
  14.  
  15. int main()
  16. {
  17. stringstream stream;
  18. string a;
  19. cout << "Введите строку: " << endl;
  20. getline(cin, a);
  21. stream.str(a);
  22. string s;
  23. int q = 0;
  24. string d;
  25. while (stream >> s)
  26. {
  27. q++;
  28. if ((s == "no") || (s == "a"))
  29. {
  30. d += ", ";
  31. }
  32.  
  33. d += s + ' ';
  34. }
  35. int k = 0, n = d.length();
  36. string temp1, temp2;
  37. for ( int i = 0; i < (d.length() - 1); i++)
  38. {
  39. if (d[i] != ',')
  40. {
  41. k++;
  42. if (d[i] != ' ')
  43. temp1 += d[i];
  44. }
  45.  
  46. else
  47. {
  48. if (k < n)
  49. {
  50. n = k;
  51. temp2 = temp1;
  52. }
  53. k = 0;
  54. temp1 = "";
  55.  
  56. }
  57. }
  58. if (k < n)
  59. {
  60. temp2 = temp1;
  61. n = k;
  62. }
  63.  
  64. cout << endl << d << endl << n << endl << temp2 << endl;
  65. return 0;
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment