Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class CandyBox {
- private:
- int cnt;
- int* candies;
- public:
- CandyBox(int cnt = 0) {
- this->cnt = cnt;
- candies = new int[cnt];
- }
- ~CandyBox() {
- delete[] candies;
- }
- CandyBox(const CandyBox& other) {
- cnt = other.cnt;
- candies = new int[cnt];
- for (int i = 0; i < cnt; i++) {
- candies[i] = other.candies[i];
- }
- }
- CandyBox operator[] (int index) const {
- return candies[index];
- }
- int count(int x) {
- int sum = 0;
- for (int i = 0; i < cnt; i++) {
- if (candies[i] == x)
- sum++;
- }
- return sum;
- }
- void read() {
- for (int i = 0; i < cnt; i++) {
- cin >> candies[i];
- }
- }
- void print() {
- for (int i = 0; i < cnt; i++) {
- cout << candies[i] << " ";
- }
- }
- int varieties() {
- int sum = 1;
- for (int i = 0; i < cnt; i++) {
- for (int j = 1; j < cnt; j++) {
- if (candies[j] < candies[j - 1]) {
- swap(candies[j], candies[j - 1]);
- }
- }
- }
- for (int i = 1; i < cnt; i++) {
- if (candies[i] != candies[i - 1]) {
- sum++;
- }
- }
- return sum;
- }
- int size() {
- this->cnt = cnt;
- return cnt;
- }
- int& at(int index) {
- return candies[index];
- }
- };
- CandyBox Arcady_process(CandyBox& b) {
- int* arr = new int[b.size()];
- for (int i = 0; i < b.size(); i++) {
- arr[i] = 0;
- }
- int tmp = 0;
- for (int i = 0; i < b.size(); i++) {
- if (b.at(i) % 2 == 0) {
- arr[tmp] = b.at(i);
- b.at(i) = 0;
- tmp++;
- }
- }
- int j = 0;
- for (int i = 0; i < b.size(); i++) {
- if (b.at(i) == 0 && arr[j] != 0) {
- b.at(i) = arr[j];
- j += 2;
- }
- }
- delete[] arr;
- return b;
- }
- CandyBox Alice_process(CandyBox& b) {
- for (int i = 0; i < b.size() / 2; i++) {
- b.at(i) = 0;
- }
- CandyBox c(b);
- for (int i = 0; i < b.size(); i++) {
- b.at(i) = 0;
- }
- int j = b.size()/2;
- for (int i = 0; i < b.size(); i += 2) {
- b.at(i) = c.at(j);
- j++;
- }
- return b;
- }
- int count_afterwards(CandyBox& b, int x) {
- CandyBox a(b);
- Alice_process(a);
- Arcady_process(b);
- return a.count(x) + b.count(x);
- }
- int main() {
- int cnt,x;
- cin >> cnt;
- CandyBox a(cnt);
- a.read();
- cin >> x;
- cout << count_afterwards(a, x);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement