Advertisement
halexandru11

atestat_15.cpp

Nov 25th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     ifstream fin("atestat.in");
  8.     ofstream fout("atestat.out");
  9.  
  10.     unsigned int n;
  11.     unsigned int a[101];
  12.     // citesc datele de intrare
  13.     // si le afisez in fisierul de iesire
  14.     fin >> n;
  15.     for(int i = 0; i < n; ++i) {
  16.         fin >> a[i];
  17.         fout << a[i] << " ";
  18.     }
  19.     fout << "\n";
  20.  
  21.     // construiesc alt vector care contine elementele din vectorul a o singura data
  22.     unsigned int m = 0;
  23.     unsigned int b[101];
  24.     unsigned int folosit[10000];
  25.     for(int i = 0; i < n; ++i) {
  26.         if(!folosit[a[i]]) {
  27.             b[m++] = a[i];
  28.             folosit[a[i]] = 1;
  29.         }
  30.     }
  31.  
  32.     // afisez elementele din vectorul creat
  33.     for(int i = 0; i < m; ++i) {
  34.         fout << b[i] << " ";
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement