PAT 1012(甲级) The Best Rank
来源:互联网 发布:小布老师linux 编辑:程序博客网 时间:2024/05/16 07:34
坑点:不要把6为的学号当int型储存,要按照字符串储存,否则如果是001101,输入1101,则按照int型可以匹配,测试点第一个就是测试这个。
#include<iostream>#include<string.h>using namespace std;int main(){int N, M;cin >> N >> M;int table[2000][4];//table[i][0],到table[i][3]依次存入总分,C,M,E的成绩char id[2000][7];//学号int rank[2000][4] = { 0 };//每位同学各科排名和总排名int best[2000][2] = { 0 };//最佳排名,和对应的科目for (int i = 0; i < N; i++){int sum = 0;cin >> id[i];id[i][6] = '\0';for (int k = 0; k < 4; k++){if (k == 0)continue;cin >> table[i][k];sum += table[i][k];}table[i][0] = sum;//计算总分存入table[i][0]}for (int i = 0; i < N; i++){int bestrank = -1;int bestcourse;for (int j = 0; j < 4; j++)//j对应科目{int max = 0;for (int k = 0; k < N; k++){if (table[i][j] < table[k][j]){if (max < table[k][j])max = table[k][j];rank[i][j]++;}}if (bestrank > rank[i][j] || bestrank == -1)//每位学生最优秀科目{bestrank = rank[i][j];bestcourse = j;}}best[i][0] = bestrank+1;//rank数组初始化为0,因此每个人的名次要加1best[i][1] = bestcourse;}for (int i = 0; i < M; i++){int k;char nid[7];cin >> nid;nid[6] = '\0';for (k = 0; k < N+1; k++){if(strcmp(nid,id[k])==0)break;}if (k != N + 1){cout << best[k][0] << ' ';switch (best[k][1]){case 0:cout << 'A'; break;case 1:cout << 'C'; break;case 2:cout << 'M'; break;case 3:cout << 'E'; break;}}elsecout << "N/A";cout << endl;}system("pause");return 0;}
阅读全文
0 0
- PAT 1012(甲级) The Best Rank
- pat甲级1012-The Best Rank
- PAT(甲级)1012. The Best Rank (25)
- PAT甲级A1012. The Best Rank (25)
- 【PAT甲级】1012. The Best Rank (25)
- PAT甲级.1012. The Best Rank (25)
- 1012. The Best Rank (25) PAT甲级
- PAT甲级1012. The Best Rank (25)
- PAT 甲级1012. The Best Rank (25)
- PAT 甲级 1012. The Best Rank
- PAT 甲级 1012. The Best Rank (25)
- PAT 甲级 1012. The Best Rank (25)
- PAT程序设计考题——甲级1012( The best rank ) C++实现
- pat 1012 The Best Rank
- pat 1012 The Best Rank
- PAT 1012 The Best Rank
- PAT 1012 The Best Rank
- 1012. The Best Rank (25)-PAT甲级真题
- harris角点检测c++代码
- iOS 在react-native中嵌入原生悬浮框
- Java 并发与多线程规范(4) 自旋锁是可重入的吗?CAS与自旋锁的关系,CAS的ABA问题,以及乐观锁,悲观锁,互斥锁,读写锁的整理
- android 数据库 数据表统计条数
- TCP粘包,拆包及解决方法
- PAT 1012(甲级) The Best Rank
- 十进制转二进制,短除法与位运算两种方法
- Java高级开发工程师面试考纲
- Android-NestedScrollingParent, NestedScrollingChild父子View 间 的 嵌套滑动
- 尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行
- mysql5.7 密码问题
- BSON与JSON的区别
- CString/string/string.h
- 错误解决:grep时出现错误 Binary file (standard input) matches