Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <time.h>
- #include <map>
- #include <utility>
- #include <string>
- using namespace std;
- int main(void) {
- list<string> l;
- string s, t;
- char c;
- //Считывание
- getline(cin, s);
- cin >> c;
- //Получение списка слов
- for (int i = 0; i < s.size(); ++ i) {
- if (s[i] == ' ') {
- if (t.size() != 0) {
- l.push_back(t);
- t.clear();
- }
- }
- else
- t.push_back(s[i]);
- }
- if (t.size() != 0)
- l.push_back(t);
- //Вывод всех слов и подсчёт нужных слов
- int cnt = 0;
- cout << "List:\n";
- for (list<string>::iterator it = l.begin(); it != l.end(); ++ it) { //Проход по списку слов
- cout << *it << "\n"; //Вывод слова
- int flag = 0;
- for (int i = 0; i < it->size(); ++ i) { //Проход по буквамслова
- if ((*it)[i] == c && i != 0 && i != it->size() - 1) //Если не первая и не последняя буква
- flag = 1;
- }
- cnt += flag;
- }
- cout << "\nAnswer: " << cnt << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement