Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <iomanip>
  6. #include <io.h>
  7. #include <string>
  8. #include <conio.h>
  9. #include <Windows.h>
  10. #pragma warning( disable : 4996 )
  11.  
  12. using namespace std;
  13.  
  14. ifstream fin;
  15. ofstream protocol;
  16. const char* name[] = { "text.txt","protocol.txt" };
  17.  
  18. struct familii {
  19. char* str;
  20. int count;
  21. };
  22. familii* fs = new familii;
  23. int nf = 0;
  24.  
  25. void addF(char* str) {
  26. familii* newF = new familii[nf + 1];
  27. memcpy(newF, fs, sizeof(familii) * nf);
  28. delete[] fs;
  29. fs = newF;
  30. fs[nf].str = new char[strlen(str) + 1];
  31. strcpy(fs[nf].str, str);
  32. fs[nf].count = 1;
  33. nf++;
  34. }
  35.  
  36. void insertF(char* str) {
  37. for (int i = 0; i < nf; i++) {
  38. if (strcmp(str, fs[i].str) == 0) {
  39. fs[i].count++;
  40. //cout << "2 " << fs[i].count << endl;
  41. return;
  42. }
  43. }
  44. addF(str);
  45. }
  46.  
  47. int main() {
  48. setlocale(LC_ALL, "rus");
  49. SetConsoleCP(1251); SetConsoleOutputCP(1251);
  50. fin.open(name[0]); protocol.open(name[1]);
  51. char c;
  52. char s[256];
  53. char T[80];
  54. protocol << "ИСХОДНЫЙ ТЕКСТ\n\n";
  55. while (fin.peek() != EOF) {
  56. fin >> s; protocol << s;
  57. insertF(s);
  58. fin.getline(T, 80); protocol << T << endl;
  59. }
  60. fin.close();
  61. protocol << "\nРЕЗУЛЬТАТЫ РАБОТЫ\n\n";
  62. int n = 0;//общее кол-во
  63. for (int i = 0; i < nf; i++) {
  64. if (fs[i].count >= 2) {
  65. protocol << fs[i].str << " - " << fs[i].count << " человека\n";
  66. n += fs[i].count;
  67. }
  68. }
  69. protocol << "Общее количество однофамильцев: " << n << endl;
  70. protocol.close();
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement