StoneHaos

dima1

Oct 6th, 2020
796
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <list>
  2. #include <iostream>
  3. #include <time.h>
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. double random_() {
  9.     return 1.0 * (rand() % 100) / (rand() % 100);
  10. }
  11.  
  12. int main(void) {
  13.     srand(time(NULL));
  14.     int n;
  15.     list<double> l;
  16.     cin >> n;
  17.  
  18.     cout << "\nList:\n";
  19.     for (int i = 0; i < n; ++ i) {
  20.         l.push_back(random_());
  21.         cout << l.back() << " ";
  22.     }
  23.     cout << "\n\n";
  24.  
  25. //Задание а
  26.     bool flag = false;
  27.     for (list<double>::iterator i = l.begin(); i != l.end(); ++ i) {
  28.         list<double>::iterator j = i;
  29.         j ++;
  30.         for (; j != l.end(); ++ j)
  31.             if (*i == *j)
  32.                 flag = true;
  33.     }
  34.     cout << "Zadanie a: " << ((flag) ? "YES" : "NO") << "\n\n";
  35.  
  36. //Задание б
  37.     l.push_front(l.back());
  38.     l.pop_back();
  39.     cout << "Zadanie b:\n";
  40.     for (list<double>::iterator i = l.begin(); i != l.end(); ++ i)
  41.         cout << *i << " ";
  42.     cout << "\n";
  43.     return 0;
  44. }
RAW Paste Data