很郁闷的一题,一定要认真读题目,特别注意这句话 Concatenate its elements to obtain one long string,,,一定要理解这句话
1 #include <iostream> 2 #include <string> 3 #include <vector> 4 #include <algorithm> 5 #include <sstream> 6 #include <numeric> 7 using namespace std; 8 9 class EllysRoomAssignmentsDiv2{ 10 public: 11 double getProbability(vector <string> ratings){ 12 string split=""; 13 string all = accumulate(ratings.begin(),ratings.end(),split); 14 stringstream sst(all); 15 vector<int> score; 16 int tmp; 17 while(sst >> tmp) score.push_back(tmp); 18 int score_elly = score[0]; 19 sort(score.begin(),score.end(),greater<int>()); 20 int cnt_elly = 0; 21 for(int i = 0 ; i < score.size(); i ++ ){ 22 if( score[i] == score_elly) { 23 cnt_elly = i;break; 24 } 25 } 26 int R = score.size()%20 ? score.size()/20+1 : score.size()/20; 27 if(R <= 1 || cnt_elly == 0 ) return 1.0; 28 else if( cnt_elly < R ) return 0.0; 29 else return 1.0/R; 30 31 } 32 };