Facebook
From Haker, 6 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 221
  1. #include "stdafx.h"
  2. #include "iostream"
  3. #include "vector"
  4. #include "map"
  5. using namespace std;
  6.  
  7. void wypisz(vector<int>liczby)
  8. {
  9.         for (int i = 0; i < liczby.size(); i++)
  10.         {
  11.                 cout << liczby[i] << ",";
  12.         }
  13.         cout << endl;
  14. }
  15.  
  16.  
  17.  
  18. int czynalezy(vector<int>liczby, int x)
  19. {
  20.         for (int i = 0; i < liczby.size(); i++)
  21.         {
  22.                 if (x == liczby[i])
  23.                 {
  24.                         return true;
  25.                 }
  26.         }
  27.         return false;
  28. }
  29.  
  30. int czyzawiera(vector<int>liczby, vector<int>numery)
  31. {
  32.         for (int i = 0; i < numery.size(); i++)
  33.         {
  34.                 if (!czynalezy(liczby, numery[i]))
  35.                 {
  36.                         return false;
  37.                 }
  38.         }
  39.         return true;
  40. }
  41.  
  42. vector<int>unikatowosc(vector<int>liczby)
  43. {
  44.         vector<int>wynik;
  45.         for (int i = 0; i < liczby.size(); i++)
  46.         {
  47.                 if (!czynalezy(wynik, liczby[i]))
  48.                 {
  49.                         wynik.push_back(liczby[i]);
  50.                 }
  51.         }
  52.         return wynik;
  53. }
  54.  
  55. int test(map<int, int>mapa, int x)
  56. {
  57.         for each(auto element in mapa)
  58.         {
  59.                 if (element.first == x)
  60.                 {
  61.                         return true;
  62.                 }
  63.         }
  64.         return false;
  65. }
  66.  
  67.  
  68. int _tmain(int argc, _TCHAR* argv[])
  69. {
  70.         int arr[] = {1,2,2,4,5,5,5,8,9};
  71.         int arr_l = end(arr) - begin(arr);
  72.         vector<int>liczby(arr, arr + arr_l);
  73.         vector<int>numery;
  74.         numery.push_back(1);
  75.         numery.push_back(5);
  76.         numery.push_back(9);
  77.         map<int, int>mapa;
  78.         mapa.insert(pair<int, int>(1, 3));
  79.         mapa.insert(pair<int, int>(4, 8));
  80.         mapa.insert(pair<int, int>(6, 9));
  81.         int x = test(mapa, 1);
  82.         cout << x << endl;
  83.         int y = czyzawiera(liczby, numery);
  84.         cout << y << endl;
  85.         wypisz(liczby);
  86.         vector<int>wynik = unikatowosc(liczby);
  87.         wypisz(wynik);
  88.         system("pause");
  89.  
  90. }
  91.  
  92.