我的生活 我的工作 我的心情 就在這裡
#include #include #include #include using namespace std;class Q102{ private: map > bin; map movecount; unsigned int MoveCount(string bin1,string bin2,string bin3) { unsigned int movecount=0; movecount+=bin[1][bin1]+bin[2][bin1]; movecount+=bin[0][bin2]+bin[2][bin2]; movecount+=bin[0][bin3]+bin[1][bin3]; return movecount; } void GetAllMoveCount() { movecount["BCG"]=MoveCount("B","C","G"); movecount["BGC"]=MoveCount("B","G","C"); movecount["CBG"]=MoveCount("C","B","G"); movecount["CGB"]=MoveCount("C","G","B"); movecount["GBC"]=MoveCount("G","B","C"); movecount["GCB"]=MoveCount("G","C","B"); } public: Q102() { for(int i=0;i<3;++i) { bin[i]["G"]=0; bin[i]["B"]=0; bin[i]["C"]=0; } } void SetGlass(unsigned int b1,unsigned int g1,unsigned int c1,unsigned int b2,unsigned int g2,unsigned int c2,unsigned int b3,unsigned int g3,unsigned int c3) { bin[0]["B"]=b1; bin[0]["G"]=g1; bin[0]["C"]=c1; bin[1]["B"]=b2; bin[1]["G"]=g2; bin[1]["C"]=c2; bin[2]["B"]=b3; bin[2]["G"]=g3; bin[2]["C"]=c3; } void ShowMin() { GetAllMoveCount(); unsigned int min=movecount["BCG"]; string minlable="BCG"; for(map::iterator iter=movecount.begin();iter!=movecount.end();++iter) { if(iter->second < min) { min=iter->second; minlable=iter->first; } } cout << minlable << " " << min << endl; } };int main(int argc, char *argv[]){ Q102 q102; unsigned int b1, g1,c1, b2,g2, c2, b3, g3, c3; while(true) { cin >> b1 >> g1 >> c1 >> b2 >> g2 >> c2 >> b3 >> g3 >> c3; if(cin.eof()) { break; } q102.SetGlass(b1,g1,c1,b2,g2,c2,b3,g3,c3); q102.ShowMin(); }}
張貼留言
沒有留言:
張貼留言