Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class CandyBox {
- int cnt;
- int* candies;
- public:
- CandyBox() {
- this->candies = NULL;
- this->cnt = 0;
- }
- ~CandyBox() {
- delete [] this->candies;
- }
- CandyBox(const CandyBox& c) {
- this->cnt = c.cnt;
- for (int i = 0; i < cnt; i++) {
- this->candies[i] = c.candies[i];
- }
- }
- void read() {
- cin >> this->cnt;
- if (this->candies) {
- delete [] this->candies;
- }
- this->candies = new int [this->cnt];
- for (int i = 0; i < this->cnt; ++i) {
- cin >> this->candies[i];
- }
- }
- void print() {
- for (int i = 0; i < this->cnt; ++i) {
- cout << this->candies[i] << " ";
- }
- }
- bool in(int data[], int size, int value) {
- for (int i = 0; i < size; ++i) {
- if (data[i] == value) {
- return true;
- }
- }
- return false;
- }
- int varietes() {
- int *data = new int[this->cnt];
- int count = 0;
- for (int i = 0; i < this->cnt; ++i) {
- if (!in(data, count, this->candies[i])) {
- data[count++] = this->candies[i];
- }
- }
- delete [] data;
- return count;
- }
- int size() {
- return this->cnt;
- }
- int& at(int index) {
- for (int i = 0; i <= index; i++) {
- if (i == index) {
- return this->candies[i];
- }
- }
- }
- };
- CandyBox Arcady_process(CandyBox b) {
- int temp_ar[b.size()];
- int temp_cnt;
- for (int i = 0; i < b.size(); i++) {
- if (!(b.at(i) % 2 == 0)) {
- temp_cnt++;
- temp_ar[temp_cnt] = i;
- }
- }
- for (int i = 1; i <= b.size(); i++) {
- if (i % 2 == 0) {
- b.at(temp_ar[i]) = 0;
- }
- }
- return b;
- };
- int main() {
- CandyBox c;
- c.read();
- Arcady_process(c);
- c.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement