Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <sstream>
- #include <cstring>
- #include <algorithm>
- using namespace std;
- int main(){
- string str = "";
- std::vector<string> sentence;
- string temp = "";
- string maxString = "";
- int resultCompare = 0;
- // forbidden symbols
- char characters[] = "0123456789";
- // word of the sentence(vector of characters in a word)
- string word = "";
- // create a stringstream
- stringstream ss;
- // get the sentence string
- getline(cin, str);
- // populate the stringstream
- ss << str;
- // get each vector(word) in the vector of strings(sentence) from the stringstream populated with the sentence
- while(ss >> word) {
- // using #include <cstring> for strlen
- // erase every character that is not allowed (from the forbidden symbols array) from the word(vector of characters)
- // using the erase-remove idiom
- for(size_t j = 0; j < strlen(characters); j++) {
- word.erase(std::remove(word.begin(), word.end(), characters[j]), word.end());
- }
- //push the vector of characters to the sentence vector of strings
- sentence.push_back(word);
- }
- // loop through the vector of strings(sentence)
- for(int i = 0; i < sentence.size(); i++) {
- // set each word to temp string
- temp = sentence[i];
- // compare temp an maxString by size of the strings
- if(temp.size() >= maxString.size()) {
- // compare tema and maxString lexicographically (using #include <algorithm>
- resultCompare = lexicographical_compare(maxString.begin(), maxString.end(), temp.begin(), temp.end());
- // if result is 0 -> first string is equal to second string lexicographically
- // if result is 1 -> first string is bigger to second string lexicographically
- // if result is negative -> first string is smaller than second string lexicographically
- if(resultCompare == 0 || resultCompare == 1) {
- // if strings equal or first string is bigger lexicographically, set maxString to temp(found the biggest string)
- maxString = temp;
- }
- }
- }
- // if vector of allowed chars(word without numbers) was found in the sentence
- // and the it is the biggest after size and lexicographical checks, output the biggest word
- if(!maxString.empty()) {
- cout << maxString << endl;
- // if not output "no noise"
- } else {
- cout << "no noise" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement