mstoyanov7

7 zad

Apr 21st, 2021
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <cctype>
  5.  
  6. std::string readInput() {
  7. std::string line;
  8. getline(std::cin, line);
  9. return line;
  10. }
  11.  
  12. void getTheNoise(std::string& line) {
  13. std::istringstream istr(line);
  14. std::string word;
  15. int maxLength = 0;
  16. std::string minValue = "";
  17.  
  18. while (istr >> word) {
  19.  
  20. std::string lastWord = "";
  21.  
  22. for (char c : word) {
  23. if (!isdigit(c)) {
  24. lastWord += c;
  25. }
  26. }
  27.  
  28. if (lastWord.size() > maxLength) {
  29. maxLength = lastWord.size();
  30. minValue = lastWord;
  31. }
  32. else if (lastWord.size() == maxLength) {
  33. if (lastWord < minValue) {
  34. minValue = lastWord;
  35. }
  36. }
  37. }
  38. if (maxLength == 0) {
  39. minValue = "no noise";
  40. }
  41.  
  42. std::cout << minValue << std::endl;
  43. }
  44.  
  45. int main() {
  46.  
  47. std::string line = readInput();
  48. getTheNoise(line);
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment