思路:
题目要求输入为总共的题数和罚分数
输入次数为一直循环输入每个人的名字和每道题的分数
用一个结构体输出每个人的成绩排名
成绩排名需要写一个判断函数用于排序,这里可以参考C++排序函数的用法
#include<string>
#include<iostream> //cin输入的库函数
#include<algorithm> //sort函数库函数
#include<stdio.h>
using namespace std;
struct student
{
string name;
int num;
int delscore;
};
bool cmp(student a,student b)
{
return a.num!=b.num? a.num>b.num:a.delscore<b.delscore;
}
//定义一个输出的结构体
int main()
{
int n,m,d,fail,time; //n为考试题数,m为每道题的罚分,fail为提交错误的次数,time为提交正确的耗时
string str;
student stu[1000];
cin>>n>>m;
d=0;
while(cin>>stu[d].name) //因为没有规定输入行数,所以用while循环输入name可以保证循环不会结束
{
stu[d].num=0; //清洗数据
stu[d].delscore=0;
for(int i=0;i<n;i++) //遍历输入n道题
{
fail=0