Advertisement
xTheEc0

4. Kolekcija. (Vad 73psl.)

Jan 12th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. /*
  2. 14
  3. 1 1 1 2 2 2 5 6 12 13 13 25 99 648
  4. 9
  5. 1 5 6 7 7 14 44 25 127
  6. */
  7.  
  8. #include <iostream>
  9. #include <fstream>
  10. using namespace std;
  11. const char duomF[] = "2.txt";
  12. const char rezF[] = "rez2.txt";
  13. const int CMax = 1001;
  14.  
  15.  
  16. void skaitymas(int A[], int R[], int &n, int &m)
  17. {
  18.     ifstream df(duomF);
  19.     int temp;
  20.  
  21.     df >> n;
  22.     for (int i = 0; i < n; i++) {df >> temp; A[temp]++;}
  23.  
  24.     df >> m;
  25.     for (int i = 0; i < m; i++) {df >> temp; R[temp]++;}
  26.  
  27.     df.close();
  28. }
  29.  
  30. void reset(int A[], int R[])
  31. {
  32.     for (int i = 0; i < 1001; i++) {A[i] = 0; R[i] = 0;}
  33. }
  34.  
  35. void sprendimas (int A[], int R[])
  36. {
  37.     ofstream rf(rezF);
  38.  
  39.     for (int i = 0; i < 1001; i++) if (A[i] > 1 && R[i] == 0) rf << i << " ";
  40.    
  41.     rf.close();
  42. }
  43.  
  44. int main ()
  45. {
  46.     int A[CMax]; int R[CMax];
  47.     int n; int m;
  48.  
  49.     reset(A, R);
  50.     skaitymas(A, R, n, m);
  51.     sprendimas(A, R);
  52.  
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement