策略有点像田忌赛马。 1,把A和B进行排序 2,遍历B,对B中每一个数找到A中第一个大于这个数的 public static int getMostBonus(int n, int teamA[], int teamB[]) {
int res=0;
Arrays.sort(teamA);
Arrays.sort(teamB);
int i=0;
int j=0;
for( ;i<teamB.length;i++){
for( ;j<teamA.length;j++){
if(teamA[j]>teamB[i]){
res+=100;
j++;
break;
}
}
if (j==teamA.length){
res-=(teamB.length-i-1)*100;
break;
}
}
return res;
}
#include<iostream> #include<string> #include<stack> using namespace std; int main() { string str; getline(cin, str); int point = str.size()-1; int right = str.size(); int left; bool flag = true; unsigned int len = str.size(); for (int i = len - 1; i >= 0; i--) { if (str[i] != ' ') { flag = false; point--; continue; } if (!flag) { flag = true; left = point; point++; while (point != right) { cout << str[point]; point++; } cout << " "; point = left - 1; right = left; } else { right = point; point--; } } point++; if (point != right) { while (point != right) { cout << str[point]; point++; } cout << " "; } cout <<'\b'; system("pause"); return 0; }