CFF认证考试|CFF认证考试 2019-09-1 小明种苹果(C++版本)

201909-1
小明种苹果
CFF认证考试|CFF认证考试 2019-09-1 小明种苹果(C++版本)
文章图片

#include #include using namespace std; int main() { int treenum, surveynum; //苹果树个数和疏果操作次数 int i, j; int all = 0, number = 0, drop = 0; //存放输出结果——剩余总苹果量、最大疏果量所在树的编号、最大疏果量 cin >> treenum >> surveynum; int **array; //每一行都存放单颗苹果树总苹果量和每轮疏果量 array = new int*[treenum]; for (i = 0; i < treenum; i++) array[i] = new int[surveynum + 1]; for (i = 0; i < treenum; i++) for (j = 0; j <= surveynum; j++) cin >> array[i][j]; for (i = 0; i < treenum; i++) for (j = 0; j <= surveynum; j++) all = all + array[i][j]; vector> p(treenum,vector(2)); //定义treenum行、两列的vector for (i = 0; i < treenum; i++)//存放每棵苹果树的编号及其疏果总量 { p[i][0] = i + 1; for (j = 1; j <= surveynum; j++) { p[i][1] = p[i][1] + array[i][j]; } } for (i = treenum - 1; i > 0; i--)//将p按照疏果量由大到小排序 for (j = 0; j <= i - 1; j++) { int temp1 = 0, temp2 = 0; if (-(p[j][1]) < -(p[i][1])) { temp1 = p[j][1]; p[j][1] = p[i][1]; p[i][1] = temp1; temp2 = p[j][0]; p[j][0] = p[i][0]; p[i][0] = temp2; } } drop = -(p[0][1]); number = p[0][0]; for (i = 0; p[i][1] == p[i + 1][1]; i++)//保证最大疏果量对应的苹果树编号最小 if (number > p[i + 1][0]) number = p[i + 1][0]; cout << all << " " << number << " " << drop << endl; delete []array; return 0; }

【CFF认证考试|CFF认证考试 2019-09-1 小明种苹果(C++版本)】CFF认证考试|CFF认证考试 2019-09-1 小明种苹果(C++版本)
文章图片

该代码没有完美得分,望大神们指点,谢谢

    推荐阅读