Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<locale>
- class solution{
- public:
- bool find(std::string word, std::string row)
- {
- for(size_t i = 0; i<word.size(); i++)
- {
- if(row.find(std::tolower(word[i])) == std::string::npos)
- {
- return false;
- }
- }
- return true;
- }
- std::vector<std::string>findWords(std::vector<std::string>&words)
- {
- std::string row1 = "qwertyuiop";
- std::string row2 = "asdfghjkl";
- std::string row3 = "zxcvbnm";
- std::vector<std::string>result;
- for(std::string & word : words)
- {
- if(find(word, row1) || find(word, row2) || find(word, row3))
- {
- result.push_back(word);
- }
- }
- return result;
- }
- };
- int main()
- {
- solution sol;
- std::string word;
- std::vector<std::string>temp;
- std::vector<std::string>input;
- int T;
- std::cout<<"how many word do you want to input"<<std::endl;
- std::cin>>T;
- for(int i=0; i<(T+1); i++)
- {
- std::getline(std::cin, word);
- input.push_back(word);
- }
- temp = sol.findWords(input);
- for(size_t i=0; i<temp.size(); i++)
- {
- std::cout<<temp[i]<<std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment