Note that you only need to connect the strings in the ratings parameter directly, without adding spaces behind each element. at the beginning, I thought that when each element is connected, it should be separated by spaces, and then duplicated elements are removed. As a result, system test has an error and debugging has not been completed for half a day. the problem is that there is no duplicate data. it can be seen that some of the topics on TopCoder seem simple, but there is actually a pitfall, and such a pitfall sample cannot be tested. After passing the sample, we will submit, and the system test will go down directly, it is worth noting that the accuracy of this question is only % 10. the Code is as follows:
#include <algorithm>#include <sstream>#include <string>#include <vector>using namespace std;/************** Program Begin *********************/class EllysRoomAssignmentsDiv2 {public: double getProbability(vector <string> ratings) {double res;int Elly;string rating = "";for (int i = 0; i < ratings.size(); i++) {rating += ratings[i];}vector <int> regs;istringstream iss(rating);int member = 0;while (iss >> member) {regs.push_back(member);}Elly = regs[0];sort(regs.begin(), regs.end(), greater <int> () );int pos = 0;for (int i = 0; i < regs.size(); i++) {if (Elly == regs[i]) {pos = i;break;}}int rooms = (regs.size() + 19) / 20;if (0 == pos) {res = 1.0;} else if (pos < rooms) {res = 0.0;} else {res = 1.0 / rooms;}return res; }};