Advertisement
Spocoman

07. The Noise and the Signal

Oct 30th, 2023
933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <sstream>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     string str;
  11.     getline(cin, str);
  12.  
  13.     istringstream ss(str);
  14.  
  15.     vector<string> noises;
  16.  
  17.     while (ss >> str) {
  18.         string noise;
  19.  
  20.         for (char c : str) {
  21.             if (!isdigit(c)) {
  22.                 noise += c;
  23.             }
  24.         }
  25.  
  26.         if (noises.size() > 0) {
  27.             if (noises.front().length() > noise.length()) {
  28.                 continue;
  29.             }
  30.             else if (noises.front().length() < noise.length()) {
  31.                 noises = {};
  32.             }
  33.         }
  34.         noises.push_back(noise);
  35.     }
  36.  
  37.     sort(noises.begin(), noises.end());
  38.  
  39.     cout << (noises.front() != "" ? noises.front() : "no noise") << endl;
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement