~cpp // no 102 - Ecological Bin Packing #include <iostream> using namespace std; void main() { int bottle[9]; // 입력되는 병 int nMove[6]; // 이동 수 int i; char * bin[6] = {"BCG", "BGC", "CBG", "CGB", "GBC", "GCB"}; int min; int index; bool isRight; while (true) { isRight = true; for (i=0; i<9; i++) { if (!(cin >> bottle[i])) { isRight = false; break; } } if (!isRight) break; nMove[1] = bottle[3]+bottle[6]+bottle[1]+bottle[7]+bottle[2]+bottle[5]; nMove[0] = bottle[3]+bottle[6]+bottle[2]+bottle[8]+bottle[1]+bottle[4]; nMove[4] = bottle[4]+bottle[7]+bottle[0]+bottle[6]+bottle[2]+bottle[5]; nMove[5] = bottle[4]+bottle[7]+bottle[2]+bottle[8]+bottle[0]+bottle[3]; nMove[2] = bottle[5]+bottle[8]+bottle[0]+bottle[6]+bottle[1]+bottle[4]; nMove[3] = bottle[5]+bottle[8]+bottle[1]+bottle[7]+bottle[0]+bottle[3]; min = nMove[0]; index = 0; for (i=1; i<6; i++) { if (min > nMove[i]) { min = nMove[i]; index = i; } } cout << bin[index] << " " << nMove[index] << endl; } }