Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <list>
- #include <iterator>
- #include <iostream>
- #include <cstdlib>
- #include <fstream>
- #include <string.h>
- using namespace std;
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- struct elem {
- char str[32];
- int s;
- };
- typedef struct elem ELEM;
- int main(int argc, char** argv) {
- list <ELEM> LS;
- list <ELEM> :: iterator it;
- ELEM constr;
- char str[32];
- ifstream file("words.txt"); //подключаемся к файлу со словами
- while (!file.eof()) { //Цикл до конца файла
- file.getline(str,sizeof(str)); //записываем слова в str
- for (it=LS.begin();it!=LS.end();it++) { //цикл для каждой ячейке списка
- if (strcmp(str,(*it).str)==0) { //условие прибавление к ячейке списка единицы в случае если такое слово в списке есть
- (*it).s++; //прибавляем единичку к нужной ячейке
- break; //прерываем цикл
- }
- }
- if (it==LS.end()) { //если слова в списке нету, (если прошлый цикл был пройден до конца, то это условие выполняется)
- constr.s=1; //заполняем данными переменную constr
- strcpy(constr.str,str);
- LS.push_back(constr); //пихаем её в список
- }
- }
- file.close();
- for (it=LS.begin();it!=LS.end() ;it++) { //вывод данных
- cout<<(*it).str<<"....."<<(*it).s<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment