Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<sstream>
- #include<cctype>
- #include<vector>
- #include<utility>
- std::vector<std::string> removePunctsFromInput(std::string& input) {
- std::vector<std::string> noPunctText;
- for (size_t i = 0; i < input.size(); i++)
- {
- if (std::ispunct(input[i]))
- {
- input.replace(i, 1, " ");
- }
- }
- //std::cout << input << std::endl;
- std::istringstream istr(input);
- std::string word;
- while (istr >> word)
- {
- noPunctText.push_back(word);
- }
- return noPunctText;
- }
- std::pair<std::string, int> readPairFromInput() {
- std::pair<std::string, int> pairInput;
- std::cin >> pairInput.first >> pairInput.second;
- return pairInput;
- }
- void printSolution(const std::vector<std::string>& noPunctText, const std::pair<std::string, int>& pairInput) {
- const size_t vecSize = noPunctText.size();
- const int compareWordSize = pairInput.first.size();
- int counterWords = 0;
- for (size_t i = 0; i < vecSize; i++)
- {
- const std::string currWord = noPunctText[i];
- const int currWordSize = noPunctText[i].size();
- // std::cout << currWordSize << std::endl;
- if (currWordSize != compareWordSize)
- {
- continue;
- }
- else if (noPunctText[i][0] != pairInput.first[0])
- {
- continue;
- }
- else
- {
- int counterLettersMatch = 0;
- for (size_t j = 0; j < currWordSize; j++)
- {
- if (noPunctText[i][j] == pairInput.first[j])
- {
- counterLettersMatch++;
- }
- }
- //std::cout << counterLettersMatch << std::endl;
- const double percentLettersMatch = ((counterLettersMatch * 1.0) / compareWordSize) * 100;
- // std::cout << percentLettersMatch << std::endl;
- if ((int)percentLettersMatch >= pairInput.second)
- {
- counterWords++;
- }
- }
- }
- std::cout << counterWords << std::endl;
- }
- int main() {
- std::string text;
- getline(std::cin, text);
- const std::vector<std::string> noPunctText = removePunctsFromInput(text);
- const std::pair<std::string, int> pairInput = readPairFromInput();
- printSolution(noPunctText, pairInput);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment