注册 登录
编程论坛 C++教室

看看我的类是怎么一回事?

心剑菩提 发布于 2008-03-16 20:37, 718 次点击
The best student

Time Limit:1000MS  Memory Limit:65536K
Total Submit:54 Accepted:14

Description

建立一个学生类,包括三个属性:老师的名字、学生的名字、成绩;其中老师、姓名为不超过15个字符的字符串,成绩为int 型;

Input

第一行输入2个整数N、M,N代表输入几个学生信息,M代表输入几个老师,接下来输入N行,每行输入一学生的老师、姓名和成绩中间用空格隔开;再输入M行,每行输入老师的姓名;

Output

按输入老师顺序输出属于相应老师的学生信息中成绩最好的一个人的信息,要求格式示例:

Sample Input


5 2
meng Liming 78
he Wanglin 56
wang Lihai 89
meng zhaofei 91
he yangshu 73
meng
wang


Sample Output


The best of meng teacher’s student is : zhaofei 91
The best of wang teacher’s student is : lihai 89


Source
1 回复
#2
心剑菩提2008-03-16 20:38
这是我的正确的代码
#include<iostream>
#include<string.h>
#include<cmath>
using namespace std;
class Rank
     {
       public:
         void readdata();
         void outputdata();
          string tea[100];
          string stu[100];
          int a[100];
          int n;
          int m;
          string com[100];
     };

  void Rank::readdata()
  {
     int i,j;
     cin>>n>>m;
     for(i=0;i<n;i++)
     {
       cin>>tea[i]>>stu[i]>>a[i];
     }
     for(j=0;j<m;j++)
     cin>>com[j];   
  }
  void Rank::outputdata()
  {
      int max[100]={0},i,j;
      string maxname[100];
     for(i=0;i<m;i++)
      for(j=0;j<n;j++)
      {
         if(com[i]==tea[j])
         {
            if(max[i]<a[j])
            {
              max[i]=a[j];
              maxname[i]=stu[j];   
            }
         }
      }
      for(i=0;i<m;i++)
      cout<<"The best of "<<com[i]<<" teacher’s student is : "<<maxname[i]<<endl;     
  }
int main()
{
      Rank c1;
      c1.readdata();
      c1.outputdata();
      system("pause");
}

[[it] 本帖最后由 心剑菩提 于 2008-3-16 21:33 编辑 [/it]]
1