请看一下出了什么问题,只有60分,python
查看原帖
请看一下出了什么问题,只有60分,python
148735
xiehuif楼主2020/9/11 01:29
# -*- coding: utf-8 -*-
n=int(input())
i=0
namelist = []
testscore = []
clsscore = []
weststu = []
headstu = []
papernum = []
while i<n:
    i+=1
    tempstr = input()
    templist = tempstr.split()
    namelist.append(templist[0])
    testscore.append(int(templist[1]))
    clsscore.append(int(templist[2]))
    headstu.append(templist[3])
    weststu.append(templist[4])
    papernum.append(int(templist[5]))
mostname = ""
themon = 0
mostmon = 0
tempmon = 0
for name in namelist:
    tempmon = 0
    i=namelist.index(name)
    if ((testscore[i]>80)&(papernum[i]>0)):
        tempmon += 8000
    if (testscore[i]>85)&(clsscore[i]>80):
        tempmon += 4000
    if testscore[i]>90:
        tempmon += 2000
    if (weststu[i]=='Y')&(testscore[i]>85):
        tempmon += 1000
    if (headstu[i]=='Y')&(clsscore[i]>80):
        tempmon += 850
    themon+=tempmon
    if mostmon<tempmon:
        mostname = name
        mostmon = tempmon
print(mostname)
print(mostmon)
print(themon)

用满分C++代码跑和这段python代码跑跑出的结果亲测是一样的,但是python的只有60分,难以理解为什么,简直难受

另贴出c++代码

#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
//新建一个类,这个类代表一个学生,即这个学生的姓名的等各项属性
class stu {
public:
	bool west;      //布尔值,代表是否是西部学生,是则为TRUE,否则为FALSE
	int clscore, stuscore, nump;       //clscore代表班级评分,stuscore代表期末评分,nump代表论文数
	char name[25] = {};    //姓名
	bool leader;     //是否为班干部

	//下面这个函数将根据学生信息返回学生的奖学金的大小

	int cash() {
		int mon = 0;
		//以 下 一 一对 应
		//院士奖学金,每人8000元,期末平均成绩高于80分(>80>80),并且在本学期内发表11篇或11篇以上论文的学生均可获得;
		//五四奖学金,每人4000元,期末平均成绩高于85( > 85 > 85),并且班级评议成绩高于80分( > 80 > 80)的学生均可获得;
		//成绩优秀奖,每人2000元,期末平均成绩高于90分( > 90 > 90)的学生均可获得;
		//西部奖学金,每人1000元,期末平均成绩高于85分( > 85 > 85)的西部省份学生均可获得;
		//班级贡献奖,每人850元,班级评议成绩高于80分( > 80 > 80)的学生干部均可获得;
		if (stuscore > 80 && nump > 0) mon = mon + 8000;
		if (stuscore > 85 && clscore > 80) mon = mon + 4000;
		if (stuscore > 90) mon = mon + 2000;
		if (stuscore > 85 && west) mon = mon + 1000;
		if (clscore > 80 && leader) mon = mon + 850;
		return mon;
	}
};

//新建一个栈,用来保存学生信息,你可以把这个namelist就当成学生的集合
stack<stu>namelist;

int main() {
	stu per;   //新建一个临时的学生,在程序运作时临时保留信息,你可以看做是一个学生的临时表格
	int num;   //学生总数
	scanf(" %d ", &num);   //读取学生总数
	//以下用于临时保留各项数据
	char west;
	int clscore, stuscore, nump;
	char leader;

	//开始数据读取	

	for (int i = 0; i < num; i++) {
		//从左向右依次是姓名,期末平均成绩,班级评议成绩,是否是学生干部,是否是西部省份学生,以及发表的论文数。
		scanf("%s %d %d %c %c %d", per.name, &stuscore, &clscore, &leader, &west, &nump);

		//将这个特定的学生各项信息写入这个临时的学生个人数据中

		per.stuscore = stuscore;
		per.clscore = clscore;
		if (west == 'Y')per.west = true; else per.west = false;
		if (leader == 'Y')per.leader = true; else per.leader = false;
		per.nump = nump;

		//将这个临时的学生表格计入到这个总名单集合中,然后这个临时学生表格的使命就完成了,下一次循环这里面的信息又会变成下一位同学的信息		

		namelist.push(per);
	}
	char mostname[25]; //建立一个用于储存拥有最多奖学金的同学的姓名的字符串
	int mostmoney = 0, money = 0, wholemon = 0;//分别储存:暂时检测到的奖学金最多的学生拥有的奖学金数额,当时正在被检测的同学的奖学金数,所有学生奖学金总数

	//构建一个循环,检查名单中所有学生的奖学金状况,并更新数据

	for (int i = 0; i < num; i++) {
		money = namelist.top().cash(); //取得一位同学的奖学金数额
		wholemon = wholemon + money; //将这个数额与先前所有同学的奖学金数额相加

		//比对当前学生的降学金数额,并与先前了解到的最大奖学金数额比对,如果当前学生大于先前得到的一位获得奖学金最多的学生的奖学金,则将当前
		//同学的奖学金数量用于代替先前那位同学的奖学金数量,并将名称录入代替先前那位学生,否则不做变更

		if (mostmoney <= money) {
			mostmoney = money;
			memcpy(mostname, namelist.top().name, sizeof(namelist.top().name));
		}

		//这位学生的数据已经处理完毕,将其从名单中划掉

		namelist.pop();
	}
	printf("%s\n%d\n%d", mostname, mostmoney, wholemon);
	return 0;
}

求求大触帮忙解答一下..

2020/9/11 01:29
加载中...