char eleft[3][7]; //the coin status of eleft char eright[3][7]; //the coin status of eright char eresult[3][7]; //the eresult of each try
boolget_result(char coin, bool isLight) { if (isLight) { for (int k = 0; k < 3; k++) //Judge 3 cases { if (eresult[k][0] == 'e') //this case is even { if (strchr(eleft[k], coin) != NULL || strchr(eright[k], coin) != NULL) { returnfalse; } } if (eresult[k][0] == 'u') //this case is up { if (strchr(eright[k], coin) == NULL) { returnfalse; } } if (eresult[k][0] == 'd') //this case is down { if (strchr(eleft[k], coin) == NULL) { returnfalse; } } } } else { for (int k = 0; k < 3; k++) //Judge 3 cases { if (eresult[k][0] == 'e') //this case is even { if (strchr(eleft[k], coin) != NULL || strchr(eright[k], coin) != NULL) { returnfalse; } } if (eresult[k][0] == 'u') //this case is up { if (strchr(eleft[k], coin) == NULL) { returnfalse; } } if (eresult[k][0] == 'd') //this case is down { if (strchr(eright[k], coin) == NULL) { returnfalse; } } } }
returntrue; };
intmain() { int case_number = 0; cin >> case_number; //Get case number for (int i = 0; i < case_number; i++) //Output the eresult of each case { for (int j = 0; j < 3; j++) { cin >> eleft[j] >> eright[j] >> eresult[j]; }
for (char j = 'A'; j <= 'L'; j++) { bool isLight = true; //The fake coin is light if (get_result(j, isLight)) cout << j << " is the counterfeit coin and it is light." << endl; isLight = false; if (get_result(j, isLight)) cout << j << " is the counterfeit coin and it is heavy." << endl; } }
intmain() { int qty_apple; cin>>qty_apple; priority_queue<int, vector<int>, greater<int>> apples; for (int i = 0; i < qty_apple; i++) { int temp_in; cin >> temp_in; apples.push(temp_in); } int sum = 0; while (true) { int t_effort = 0; t_effort += apples.top(); apples.pop(); t_effort += apples.top(); apples.pop(); sum += t_effort; if (apples.empty()) break; apples.push(t_effort); } cout << sum << endl; return0; }
intmain() { //Get case number int case_number = 0; cin >> case_number; //Get input numbers of each case //开始输出结果 for (int i = 0; i < case_number; i++) {
string num_a; string num_b; cin >> num_a; cin >> num_b; //Start caculate //Confirm length int length = 0; if (num_a.length() >= num_b.length()) { length = num_a.length() + 1; } elseif (num_a.length() < num_b.length()) { length = num_b.length() + 1; } //Creat result vector<int> result(length); int nextline = 0; //进位 int ifline = 0; int Tresult = 0; //每位结果 int numberA = 0; //A的位 int numberB = 0; //B的位 //开始读数 for (int j = 0; j < length; j++) { numberA = (num_a.length() - j - 1); //A读数的位 numberB = (num_b.length() - j - 1); //B读数的位 int tempA = 0; //A临时读数 int tempB = 0; //B临时读数 //读A if (numberA >= 0) { tempA = num_a[numberA]; tempA = tempA - '0'; } //读B if (numberB >= 0) { tempB = num_b[numberB]; tempB = tempB - '0'; } //Input result int tempR = 0;
boolcompare(int a, int b) { return president[a][bits_number] > president[b][bits_number]; };
intmain() { int number = 0; cin >> number; for (int i = 0; i < number; i++) //Get the votes of president { cin >> president[i]; } //ok,let's compare queue<int> president_list; // the presidents left
int maxbit = 0; // the max votes bit president
for (int i = 0; i < number; i++) //get the bits of each president { int temp_bits = 0; for (int j = 0; j < 100; j++) // get the bits { if (president[i][j] != 0) { temp_bits++; } else { break; } } //this guy's bit has been recorded if (temp_bits >= maxbit) {
president_list.push(i); if (temp_bits > maxbit) { president_list = queue<int>(); president_list.push(i); } maxbit = temp_bits; } } //WARNING: THE NUMBER OF PRESIDENT MUST BE PLUSED ONE! //now,compare the president in queue! vector<int> last_list; while (!president_list.empty()) { last_list.push_back(president_list.front()); president_list.pop(); } for (int i = 0; i < maxbit; i++) { bits_number = i; sort(last_list.begin(), last_list.end(), compare); int erase_bit = president[last_list[0]][i];
for (auto it = last_list.begin(); it != last_list.end(); it++) { cout << ""; if (president[*it][i] < erase_bit) { last_list.erase(it); it--; cout << ""; } } } cout << last_list[0] + 1 << endl; for (int i = 0; i < maxbit; i++) { cout << president[last_list[0]][i]; }