标签:des style class blog code color
4 5 25 10 10 12 13 15 CS004 3 5 1 3 CS003 5 2 4 1 3 5 CS002 2 1 2 CS001 3 2 3 5 1 2 40 10 30 CS001 1 2 2 3 20 10 10 10 CS000000000000000001 0 CS000000000000000002 2 1 2 0
3 CS003 60 CS001 37 CS004 37 0 1 CS000000000000000002 20
思路:都会的思路;
不是思路难,是有点繁的题目,速度是关键。
这样的题目是用来训练细心和编码速度的。
#include <cstdio> #include <cstdlib> #include <algorithm> using namespace std; struct Stu { char *num; int grade; bool operator<(const Stu b) const { if (grade == b.grade) return strcmp(num, b.num) == -1; return grade > b.grade; } }; Stu stus[1001];//N int grades[12];//M char stuNum[22]; int main() { int N, M, G; while (scanf("%d %d %d", &N, &M, &G) == 3) { for (int i = 1; i <= M; i++) { scanf("%d", &grades[i]); } int count = 0; for (int i = 0; i < N; i++) { int totalGra = 0, totalNum = 0, m, id; scanf("%s %d", stuNum, &m); for (int j = 0; j < m; j++) { scanf(" %d", &id);//没看清楚题意就动手,以至浪费时间 totalGra += grades[id]; } if (totalGra >= G) { stus[count].grade = totalGra; stus[count].num = (char *) malloc(sizeof(stuNum)+1); strcpy(stus[count].num, stuNum); count++; } } sort(stus, stus+count); printf("%d\n", count); for (int j = 0; j < count; j++) { printf("%s ", stus[j].num); printf("%d\n", stus[j].grade); free(stus[j].num); } } return 0; }
标签:des style class blog code color
原文地址:http://blog.csdn.net/kenden23/article/details/31013775