Advertisement
CosminVarlan

Generator perechi (fara repetitie)

Mar 22nd, 2025 (edited)
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. #include <time.h>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. ofstream fout("data.out");
  10.  
  11. int a=0,b=30; /// capetele intervalului perechilor
  12. int cnt=500, poz=0;
  13. int sorted=0;
  14.  
  15.  
  16.  
  17. struct pereche{
  18.     int x, y;
  19. } p[200001];
  20.  
  21.  
  22. int cmp(pereche p, pereche q){
  23.     return ((p.x<q.x) || (p.x==q.x && p.y<q.y));
  24. }
  25.  
  26. int main()
  27. {
  28.     srand(time(0));
  29.     while(poz<cnt){
  30.         p[poz].x = rand()%(b-a)+a;
  31.         p[poz].y = rand()%(b-a)+a;
  32.         int gasit=0;
  33.         for(int i=0; i<poz && !gasit; i++)
  34.         {
  35.             if (p[i].x==p[poz].x && p[i].y==p[poz].y)
  36.             {
  37.                 gasit=1;
  38.             }
  39.         }
  40.         if (!gasit) {
  41.             poz++;
  42.         }
  43.     }
  44.  
  45.     if (sorted) sort(p,p+cnt,cmp);
  46.  
  47.     for(int i=0; i<cnt; i++)
  48.         fout << p[i].x << ' ' << p[i].y << '\n';
  49.     return 0;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement