TugOfWar/ ¶
150/200 고 . 고.
급기 꿔기 고...-_-ㅋ;;
급기 꿔기 고...-_-ㅋ;;
~cpp #include <iostream> using namespace std; const int MAX= 100; int maxToZero(int input[]); // 0 꾸 int returnAver(int input[]); void main(){ int weight[MAX] = {0}; int outA[MAX] = {0}; int outB[MAX] = {0}; int teamA, teamB; teamA = teamB = 0; int aver = 0; int maxInInput = 0; int N = 0; int inputN = 0; int input = 0; int A, B; A = B = 0; cin>>N; //23478 for(int n = 0; n< N; n++) { cin.get(); cin>> inputN; for(input =0; input<inputN; input++){ cin>> weight[input]; } cin.get(); teamA = teamB = A = B = 0; aver = returnAver(weight); for(int cycle=0; cycle < MAX; cycle++){ maxInInput = maxToZero( weight); if( teamA + maxInInput == aver ){ teamA += maxInInput; }else if( teamB + maxInInput == aver ){ teamB += maxInInput; }else if( teamA < teamB ){ teamA += maxInInput; }else{ teamB += maxInInput;; } } outA[n] = teamA; outB[n] = teamB; } for(n=0; n<N; n++) cout<<outA[n]<<" "<<outB[n]<<endl; } int maxToZero(int * weight){ int max = 0; int maxsIndex = 0; for(int cycle=0; cycle < MAX; cycle++){ if(max < weight[cycle]){ max = weight[cycle]; maxsIndex = cycle; } } weight[ maxsIndex ] = 0; return max; } int returnAver(int * weight){ int sum =0; for(int cycle=0; cycle<MAX ; cycle++){ sum += weight[cycle]; } return ( sum / 2); }