The+candy+war

Source Code C++ code format="cpp"
 * 1) include

using namespace std;

bool IsAllSame(int arr[], int len) {   int t = arr[0]; for(int i = 0; i < len; i++) {       if(arr[i] != t)        { return false; }   }    return true; }

void MakeEven(int arr[], int len) {   for(int i = 0; i < len; i++) {       if(arr[i] % 2 != 0) {           arr[i]++; }   } }

void PassHalf(int arr[], int len) {   for(int i = 0; i < len; i++) {       arr[i] /= 2; }

int* temp = new int[len];

temp[0] = arr[len - 1]; for(int i = 0; i < len - 1; i++) {       temp[i + 1] = arr[i]; }

for(int i = 0; i < len; i++) {       arr[i] += temp[i]; }

delete temp; }

int main {   int T;    cin >> T;

for(int i = 0; i < T; i++) {       int N;        cin >> N;

int *arr = new int[N];

for(int j = 0; j < N; j++) {           cin >> arr[j]; }

int count = 0;

MakeEven(arr, N); while(!IsAllSame(arr, N)) {           PassHalf(arr, N); MakeEven(arr, N);

count++; }

delete arr;

cout << count << endl; }

return 0; } code

Comment 단순한 배열 조작 문제이다.