Advertisement
newvol

birthday code

Jan 28th, 2023
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | Gaming | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class CandyBox {
  4.     int cnt;
  5.     int* candies;
  6. public:
  7.     CandyBox() {
  8.         this->candies = NULL;
  9.         this->cnt = 0;
  10.     }
  11.     ~CandyBox() {
  12.         delete [] this->candies;
  13.     }
  14.     CandyBox(const CandyBox& c) {
  15.         this->cnt = c.cnt;
  16.         for (int i = 0; i < cnt; i++) {
  17.             this->candies[i] = c.candies[i];
  18.         }
  19.     }
  20.    
  21.     void read() {
  22.         cin >> this->cnt;
  23.         if (this->candies) {
  24.             delete [] this->candies;
  25.         }
  26.         this->candies = new int [this->cnt];
  27.         for (int i = 0; i < this->cnt; ++i) {
  28.             cin >> this->candies[i];
  29.         }
  30.     }
  31.     void print() {
  32.         for (int i = 0; i < this->cnt; ++i) {
  33.             cout << this->candies[i] << " ";
  34.         }
  35.     }
  36.     bool in(int data[], int size, int value) {
  37.         for (int i = 0; i < size; ++i) {
  38.             if (data[i] == value) {
  39.                 return true;
  40.             }
  41.         }
  42.         return false;
  43.     }
  44.     int varietes() {
  45.         int *data = new int[this->cnt];
  46.         int count = 0;
  47.         for (int i = 0; i < this->cnt; ++i) {
  48.             if (!in(data, count, this->candies[i])) {
  49.                 data[count++] = this->candies[i];
  50.             }
  51.         }
  52.         delete [] data;
  53.         return count;
  54.     }
  55.     int size() {
  56.         return this->cnt;
  57.     }
  58.     int& at(int index) {
  59.         for (int i = 0; i <= index; i++) {
  60.             if (i == index) {
  61.                 return this->candies[i];
  62.             }
  63.         }
  64.     }
  65. };
  66.  
  67. CandyBox Arcady_process(CandyBox b) {
  68.     int temp_ar[b.size()];
  69.     int temp_cnt;
  70.     for (int i = 0; i < b.size(); i++) {
  71.         if (!(b.at(i) % 2 == 0)) {
  72.             temp_cnt++;
  73.             temp_ar[temp_cnt] = i;
  74.         }
  75.     }
  76.     for (int i = 1; i <= b.size(); i++) {
  77.         if (i % 2 == 0) {
  78.             b.at(temp_ar[i]) = 0;
  79.         }
  80.     }
  81.     return b;
  82. };
  83.  
  84. int main() {
  85.     CandyBox c;
  86.     c.read();
  87.     Arcady_process(c);
  88.     c.print();
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement