标签:int names flag bool code sys 初步 its alt
#include <bits/stdc++.h> #include<math.h> using namespace std; const int MAX_LEN = 2005; //const int MAX_D = 31; struct student{ int id; int Cgrade; int Mgrade; int Egrade; int Agrade; }stu[MAX_LEN]; int main(){ int n,m; scanf("%d%d",&n,&m); int temp[m]; for(int i =0;i<n;++i){ scanf("%d",&stu[i].id); scanf("%d",&stu[i].Cgrade); scanf("%d",&stu[i].Mgrade); scanf("%d",&stu[i].Egrade); stu[i].Agrade = (stu[i].Cgrade + stu[i].Mgrade + stu[i].Egrade)/3; } for(int i = 0;i<m;++i){ scanf("%d",&temp[i]); } int result = 0; int count = 1; int digit = 0; bool flag = false; for(int i =0;i<m;++i){ for(int j =0;j<n;++j){ if(temp[i] == stu[j].id){ digit = j; flag = true; } } if(flag == false){ printf("N/A\n"); continue; } else{ if(stu[digit].Cgrade != stu[digit].Mgrade && stu[digit].Mgrade != stu[digit].Egrade){ result = max(stu[digit].Cgrade,max(stu[digit].Egrade,stu[digit].Mgrade)); if(result == stu[digit].Cgrade){ for(int k=0;k<n;++k){ if(stu[k].Cgrade > result){ count++; } } printf("%d C\n",count); count = 1; flag = false; continue; } if(result == stu[digit].Egrade){ for(int k=0;k<n;++k){ if(stu[k].Egrade > result){ count++; } } printf("%d E\n",count); count = 1; flag = false; continue; } if(result == stu[digit].Mgrade){ for(int k=0;k<n;++k){ if(stu[k].Mgrade > result){ count++; } } printf("%d M\n",count); count = 1; flag = false; continue; } }else{ result = stu[digit].Agrade; for(int k=0;k<n;++k){ if(stu[k].Agrade > result){ count++; } } printf("%d A\n",count); count = 1; flag = false; continue; } } } system("pause"); return 0; }
算法初步——排序 A1012.The Best Rank(25)
标签:int names flag bool code sys 初步 its alt
原文地址:https://www.cnblogs.com/JasonPeng1/p/12152048.html