Advertisement
amarek

Pixeli

Jul 4th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.98 KB | None | 0 0
  1. //02.07.2019.
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. template<typename Tip>
  8. int countUnique(Tip* polje, int n)
  9. {
  10.     int unique = 0;
  11.     for (int i = 0; i < n; i++)
  12.     {
  13.         int brojac = 0;
  14.         for (int j = 0; j < n; j++)
  15.         {
  16.             if (polje[i] == polje[j])
  17.             {
  18.                 brojac++;
  19.             }
  20.         }
  21.         if (brojac == 1)
  22.         {
  23.             unique++;
  24.         }
  25.     }
  26.     return unique;
  27. }
  28.  
  29. class Acceleration
  30. {
  31.     int x, y;
  32.     double z;
  33. public:
  34.     Acceleration() : x(0), y(0), z(0) {}
  35.     Acceleration(int a, int b, double c) : x(a), y(b), z(c){}
  36.     friend bool operator== (const Acceleration& ref1, const Acceleration& ref2)
  37.     {
  38.         return ref1.x == ref2.x && ref1.y == ref2.y && ref1.z == ref2.z;
  39.     }
  40. };
  41.  
  42. class Iznimka : public runtime_error
  43. {
  44.     double energyPerOps;
  45. public:
  46.     Iznimka(double energy) : energyPerOps(energy), runtime_error("ERROR") {}
  47.     int getEnergyPerOps() const
  48.     {
  49.         return energyPerOps;
  50.     }
  51. };
  52.  
  53. class Processor
  54. {
  55.     int mCoreCount;
  56.     int mBaseOpsPerSecond;
  57.     int mCurrentOpsPerSecond;
  58.     int mRestore;
  59. public:
  60.     Processor(int core, int base, int current) : mCoreCount(core), mBaseOpsPerSecond(base), mCurrentOpsPerSecond(current), mRestore(mBaseOpsPerSecond){}
  61.     Processor(int core, int base) : mCoreCount(core), mBaseOpsPerSecond(base), mCurrentOpsPerSecond(base), mRestore(mBaseOpsPerSecond) {}
  62.  
  63.     void boost()
  64.     {
  65.         mBaseOpsPerSecond += 0.1;
  66.     }
  67.  
  68.     void restore()
  69.     {
  70.         mBaseOpsPerSecond = mRestore;
  71.     }
  72.  
  73.     double dimesion(int redak, int stupac, int opsPerPixel)
  74.     {
  75.         int pixeli = redak * stupac;
  76.         int ops = pixeli * opsPerPixel;
  77.         return (ops / mBaseOpsPerSecond) / 60;
  78.     }
  79.  
  80.     int getBaseOps () const
  81.     {
  82.         return mBaseOpsPerSecond;
  83.     }
  84.  
  85.     void setBaseOps(int vrijed)
  86.     {
  87.         mBaseOpsPerSecond = vrijed;
  88.     }
  89. };
  90.  
  91. double usteda(Processor proc, int* polje, int vel)
  92. {
  93.     double vrijeme = 0;
  94.     double vrijeme2 = 0;
  95.     for (int i = 0; i < vel; i++)
  96.     {
  97.         vrijeme += polje [i] / proc.getBaseOps() ;
  98.     }
  99.     proc.boost();
  100.     for (int i = 0; i < vel; i++)
  101.     {
  102.         vrijeme2 += polje[i] / proc.getBaseOps();
  103.     }
  104.     return (vrijeme - vrijeme2) / 60;
  105. }
  106.  
  107. void demo()
  108. {
  109.     Processor fryzen5(6, 24);
  110.     fryzen5.boost();
  111.     fryzen5.restore();
  112. }
  113.  
  114. class EnergyAwareProcessor : public Processor
  115. {
  116.     double eneryPerOps, limit;
  117. public:
  118.     EnergyAwareProcessor(double energy, double lim, int core, int base, int current) : eneryPerOps(energy), limit(lim), Processor(core, base, current){}
  119.     bool provjera()
  120.     {
  121.         return eneryPerOps <= limit;
  122.     }
  123.  
  124.     double dimesion(int redak, int stupac, int opsPerPixel)
  125.     {
  126.         if (!provjera())
  127.         {
  128.             setBaseOps((3 / 4)*getBaseOps());
  129.         }
  130.         int pixeli = redak * stupac;
  131.         int ops = pixeli * opsPerPixel;
  132.         return (ops / getBaseOps()) / 60;
  133.     }
  134. };
  135.  
  136. int main()
  137. {
  138.     int data[] = { 1, 2, 3, 3, 3, 4 };
  139.     cout << countUnique(data, 6) << endl;
  140.     Acceleration accelerations[] = { Acceleration(), Acceleration (0, 0, 9.81), Acceleration(0, 0, 9.81)};
  141.     cout << countUnique(accelerations, 3) << endl;
  142.  
  143.     int polje[] = { 1, 2, 3, 3, 4, 5 };
  144.     cout << countUnique(polje, 6) << endl;
  145.     int n;
  146.     cin >> n;
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement