Advertisement
Dorreli

Untitled

Jan 19th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <stdio.h>
  4. using namespace std;
  5.  
  6. void fill_in(int* a, const int N, ifstream& file)
  7. {
  8. for (int i = 0; i < N; i++)
  9. {
  10. file >> a[i];
  11. cout << a[i] << " | ";
  12. }
  13. }
  14.  
  15. void coincid(int* a, int* b, int N, int M)
  16. {
  17. int* c;
  18. c = new int[N];
  19. int kk = 0, per = 0;
  20. cout << endl << "Совпадающие значения: ";
  21. for (int i = 0; i < N; i++)
  22. {
  23. int k_sovp = 0;
  24. for (int j = 0; j < M; j++)
  25. {
  26. if (a[i] == b[j])
  27. {
  28. k_sovp++;
  29. per++;
  30. if (per == 2) //встретилось первый раз два раза
  31. {
  32. c[kk] = a[i];
  33. cout << c[kk] << " | ";
  34. kk++;
  35. }
  36. if ((per > 2)&&(k_sovp == 2))
  37. {
  38. int k_sovp_c = 0;
  39. for (int k = 0; k <= kk; k++)
  40. {
  41. if (c[k] == a[i]) k_sovp_c++;
  42. }
  43. if (k_sovp_c == 0)
  44. {
  45. c[kk] = a[i];
  46. cout << c[kk] << " | ";
  47. kk++;
  48. }
  49. }
  50. }
  51. }
  52. }
  53. cout << endl;
  54. }
  55.  
  56. int main()
  57. {
  58. setlocale(0, "Rus");
  59. ifstream file1("J:\\Универ\\Программирование\\Практика_txt\\z_8_1.txt");
  60. ifstream file2("J:\\Универ\\Программирование\\Практика_txt\\z_8_2.txt");
  61. if ((!file1) && (!file2))
  62. {
  63. cout << "Один или оба файла не открыты" << endl;
  64. system("pause");
  65. return 0;
  66. }
  67. else
  68. {
  69. cout << "Файлы открыты" << endl;
  70. const int N = 10;
  71. int F[N];
  72. cout << "Массив F: " << endl;
  73. fill_in(F, N, file1);
  74. const int M = 40;
  75. int D[M];
  76. cout << endl << "Массив D: " << endl;
  77. fill_in(D, M, file2);
  78. coincid(F, D, N, M);
  79. system("pause");
  80. return 0;
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement