Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <cctype>
- std::string readInput() {
- std::string line;
- getline(std::cin, line);
- return line;
- }
- void getTheNoise(std::string& line) {
- std::istringstream istr(line);
- std::string word;
- int maxLength = 0;
- std::string minValue = "";
- while (istr >> word) {
- std::string lastWord = "";
- for (char c : word) {
- if (!isdigit(c)) {
- lastWord += c;
- }
- }
- if (lastWord.size() > maxLength) {
- maxLength = lastWord.size();
- minValue = lastWord;
- }
- else if (lastWord.size() == maxLength) {
- if (lastWord < minValue) {
- minValue = lastWord;
- }
- }
- }
- if (maxLength == 0) {
- minValue = "no noise";
- }
- std::cout << minValue << std::endl;
- }
- int main() {
- std::string line = readInput();
- getTheNoise(line);
- }
Advertisement
Add Comment
Please, Sign In to add comment