本帖最后由 行客 于 2019-2-28 18:09 编辑
这个代码错误太多了。#include<iostream>
using namespace std;
typedef struct
{
char name[11];
char studentnumber[11];
int credit;
}student;
int main()
{
int n;
cin>>n;
student *a = new student[n];
int credits[101] ={0};
for(int i=0;i<n;i++)
{
cin>>a[i].name>>a[i].studentnumber>>a[i].credit;
}
for(int i=0;i<n;i++)
{
if(a[i].credit>-1&&a[i].credit<101)
credits[a[i].credit]++;
else
return 0;
}
for(int i=0;i<n;i++)
{
if(credits[a[i].credit]>1)
return 0;
}
int min = 101,max = -1,minn=0,maxn=0;
for(int i=0;i<n;i++)
{
if(max<a[i].credit)
{
max = a[i].credit;
maxn = i;
}
if(min>a[i].credit)
{
min = a[i].credit;
minn = i;
}
}
cout<<a[maxn].name<<" "<<a[maxn].studentnumber<<endl;
cout<<a[minn].name<<" "<<a[minn].studentnumber;
delete []a;
system("pause");
return 0;
}
|