Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <stdlib.h>
- #include <stdio.h>
- #include <iomanip>
- #include <io.h>
- #include <string>
- #include <conio.h>
- #include <Windows.h>
- #pragma warning( disable : 4996 )
- using namespace std;
- ifstream fin;
- ofstream protocol;
- const char* name[] = { "text.txt","protocol.txt" };
- struct familii {
- char* str;
- int count;
- };
- familii* fs = new familii;
- int nf = 0;
- void addF(char* str) {
- familii* newF = new familii[nf + 1];
- memcpy(newF, fs, sizeof(familii) * nf);
- delete[] fs;
- fs = newF;
- fs[nf].str = new char[strlen(str) + 1];
- strcpy(fs[nf].str, str);
- fs[nf].count = 1;
- nf++;
- }
- void insertF(char* str) {
- for (int i = 0; i < nf; i++) {
- if (strcmp(str, fs[i].str) == 0) {
- fs[i].count++;
- //cout << "2 " << fs[i].count << endl;
- return;
- }
- }
- addF(str);
- }
- int main() {
- setlocale(LC_ALL, "rus");
- SetConsoleCP(1251); SetConsoleOutputCP(1251);
- fin.open(name[0]); protocol.open(name[1]);
- char c;
- char s[256];
- char T[80];
- protocol << "ИСХОДНЫЙ ТЕКСТ\n\n";
- while (fin.peek() != EOF) {
- fin >> s; protocol << s;
- insertF(s);
- fin.getline(T, 80); protocol << T << endl;
- }
- fin.close();
- protocol << "\nРЕЗУЛЬТАТЫ РАБОТЫ\n\n";
- int n = 0;//общее кол-во
- for (int i = 0; i < nf; i++) {
- if (fs[i].count >= 2) {
- protocol << fs[i].str << " - " << fs[i].count << " человека\n";
- n += fs[i].count;
- }
- }
- protocol << "Общее количество однофамильцев: " << n << endl;
- protocol.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement