~cpp
//2. 재활용 용기 ì €ìž¥ë¬¸ì œ
//기본 아�디어
//--->재활용 통ì�˜ 병ì�˜ 갯수를 ìš°ì„ ëª¨ë‘� ë�”한다. total변수ì—� 넣는다.
//--->��� 재활용 통�서 서로 다른색깔� 병� 모���때� 조합�
//가장 � 수� 조합� 찾아낸다. max()함수를 통해 리턴값� 얻는다.
#include<iostream>
using namespace std;
int container[9]; //용기ì—� 들어있는 병ì�„ ìž…ë ¥ 받는다.
int total=0; //용기� 들어있는 병� �개수를 센다.
int ch_number; //최소 ì�´ë�™ 횟수를 ì €ìž¥í•œë‹¤.
char bgc[3]={'B','G','C'};
char save[4]={"NNN"}; //나중ì—� 결과값ì�„ ì¶œë ¥ì‹œ 사용
int max(int* array);
void main()
{
cout<<"용기� 담겨 있는 병� 개수를 차례대로 넣으세요"<<endl;
for(int i=0 ; i<9 ; i++)
{
cin>>container[i];
total+=container[i];
}
ch_number = total - max(container);
cout<<endl;
cout<<save<<" "<<ch_number;
cout<<endl;
}
int max(int* array)
{
int temp=0;//ê°�ê°�ì�˜ ì¡°í•©ì—� 대한 현재값ì�„ ì €ìž¥í•œë‹¤.
int max=0; //여러 ì¡°í•©ì—� 대해 가장 í�° ê°’ì�„ ì €ìž¥í•œë‹¤.
for(int i=0 ; i<3 ; i++)
{
for(int j=3 ; j<6 ; j++)
{
if(j%3 == i)
continue;
else
{
temp+=array[i];
temp+=array[j];
temp+=array[12-(i+j)];
}
if(temp > max)
{
max=temp;
save[0]=bgc[i];
save[1]=bgc[(j%3)];
save[2]=bgc[3-((j%3)+i)];
}
temp=0;
}
}
return max;
}