【发布时间】:2020-04-21 15:24:08
【问题描述】:
得分最高的击球手姓名 - C++
板球队的 N 名击球手得分作为输入传递给程序。程序必须打印得分最高的击球手的名字。 (你可以假设没有两个击球手会是最佳射手)
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv)
{
//Defines no of batsmen
int n;
cin>>n;
//Define names of batsmen and their runs
string s[100];
int r[100];
//Getting inputs
for(int i=0;i<n;i++){
scanf("%s,%d",&s[i],&r[i]);
}
// //Assign a value to int max variable
int max=r[0];
int location=0;
//find max value
for(int i=1;i<n;i++){
if(r[i] > max){
max = r[i];
location = i;
}
}
cout<<s[location];
}
输入格式:第一行表示 N 的值。接下来的 N 行将包含击球手的姓名和得分(均以逗号分隔)。
输出格式:第一行包含得分最高的击球手的名字。
示例输入/输出 1:
Input:
5
BatsmanA,45
BatsmanB,52
BatsmanC,12
BatsmanD,9
BatsmanE,78
Output: BatsmanE
【问题讨论】:
-
您好,所以不会完成作业,但我们可以回答您可能对编程提出的具体问题。请编辑此内容,以便您询问一个概念。
-
我还可以推荐一个good C++ book吗?因此,您可以学习如何编写正确的 C++,而不是这种奇怪的 C 函数和样式混合。