Uva12412
来源:互联网 发布:火山移动编程破解版 编辑:程序博客网 时间:2024/06/06 18:56
模拟//代码还没过..不知道错哪了,放两天改//现在已正确
3.31写完的代码。
4.15更正,在网上找了正确的代码对拍,终于把错找出来了。。。
题意:就是模拟一个c语言程序设计里的 个人信息管理系统,细节给的很详细,输入输出都是要按他的规范来,之前错就是因为一个小小的输出的问题。顺便学习了一下对拍的批文件怎么写。
思路: 题意就是总体的思路,必须得有一个具体的框架,然后一个功能一个功能实现与调试。注意EPS的使用,因为浮点数运算或比较可能会出现我们并不期望的结果。
c语言程序设计
#include <cstdio>#include <iostream>#include <cstring>#include <vector>#include <algorithm>using namespace std;#define maxn 1000005const double EPS = 1e-5;struct student{ char id[3][25]; int course[4]; double pj; student(){} student(char a[3][25],int b[4]) { for(int i = 0; i < 3; i++) { for(int j = 0; j < 25; j++) id[i][j] = a[i][j]; } for(int i = 0; i < 4 ; i++) course[i] = b[i]; }}data[maxn];int Size = 0;int Fin(char s[25],int a){ for(int i = 0; i < Size; i++) if(strcmp(data[i].id[a],s) == 0) return i; return -1;}int pm(int id){ int num = 1; int temp = 0; for(int i = 0; i < 4 ; i++) temp += data[id].course[i]; int flag = 0; for(int i = 0; i < Size; i++) { int com = 0; for(int j = 0; j < 4 ; j++) com += data[i].course[j]; if(com > temp) num++; } return num;}void init(){ printf("Welcome to Student Performance Management System (SPMS).\n\n"); printf("1 - Add\n"); printf("2 - Remove\n"); printf("3 - Query\n"); printf("4 - Show ranking\n"); printf("5 - Show Statistics\n"); printf("0 - Exit\n"); printf("\n");}int add() //增加{ while(1) { char id[3][25]; int co[4]; printf("Please enter the SID, CID, name and four scores. Enter 0 to finish.\n"); scanf("%s",id[0]); if(id[0][0] == '0' && strlen(id[0]) == 1) return 0; scanf("%s%s",id[1],id[2]); for(int i = 0; i < 4 ; i++) scanf("%d",&co[i]); if(Fin(id[0],0) == -1) data[Size++] = student(id,co); else printf("Duplicated SID.\n"); } return 1;}int query() //查询{ while(1) { printf("Please enter SID or name. Enter 0 to finish.\n"); char x[25]; scanf("%s",x); if(x[0] == '0' && strlen(x) == 1) break; int ans = 0; if(x[0] >= 'A' && x[0] <= 'Z') { for(int id = 0; id < Size; id++) { if(strcmp(data[id].id[2],x) != 0) continue; int sum = 0; printf("%d %s %s %s ",pm(id),data[id].id[0],data[id].id[1],data[id].id[2]); for(int a = 0; a < 4; a ++) { sum += data[id].course[a]; printf("%d ",data[id].course[a]); } printf("%d %.2f\n",sum,(double)sum/4.0+EPS); } } else { for(int id = 0; id < Size ;id++) { if(strcmp(data[id].id[0],x) != 0) continue; printf("%d %s %s %s ",pm(id),data[id].id[0],data[id].id[1],data[id].id[2]); int sum = 0; for(int a = 0; a < 4; a ++) { sum += data[id].course[a]; printf("%d ",data[id].course[a]); } printf("%d %.2f\n",sum,(double)sum*1.0/4.0+EPS); } } } return 1;}int dq() //删除{ while(1) { printf("Please enter SID or name. Enter 0 to finish.\n"); char x[25]; scanf("%s",x); if(x[0] == '0' && strlen(x) == 1) break; int ans = 0; if(x[0]>='A' && x[0] <= 'Z') { for(int id = 0; id < Size; id++) { if(strcmp(data[id].id[2],x) != 0){ continue;} for(int a = id; a < Size; a++) data[a] = data[a+1]; ans++; Size--; id= id-1; } } else { for(int id = 0; id < Size ;id++) { if(strcmp(data[id].id[0],x) != 0) continue; for(int a = id; a < Size; a++) data[a] = data[a+1]; ans++;Size --;; } } printf("%d student(s) removed.\n",ans); } return 1;}int ran(){ printf("Showing the ranklist hurts students' self-esteem. Don't do that.\n"); return 0;}int sa[maxn][4];int sta() //统计{ printf("Please enter class ID, 0 for the whole statistics.\n"); int pnum[4] = {0}; int ma[4] = {0}; int pass[5] = {0}; int rnum = Size; char s[25]; scanf("%s",s); if(s[0] == '0' && strlen(s) == 1) { for(int i = 0; i < Size; i++) { int num = 0; for(int j = 0; j < 4; j++) { ma[j] += data[i].course[j]; if(data[i].course[j] > 59) { pnum[j]++; num++; } } for(int j = num; j >= 1; j--) pass[j]++; } } else { for(int i = 0; i <Size; i++) { if(strcmp(data[i].id[1],s) != 0) {rnum --;continue;} int num = 0; for(int j = 0; j < 4 ; j++) { ma[j] += data[i].course[j]; if(data[i].course[j] > 59) { pnum[j]++; num++; } } for(int j = num; j >= 1; j--) pass[j]++; } } for(int i = 0; i < 4 ; i++) { double ans = 0; if(rnum == 0) ans = 0; else ans = (double)ma[i]/(rnum)*1.0 + EPS; if(i == 0) printf("Chinese\n"); if(i == 1) printf("Mathematics\n"); if(i == 2) printf("English\n"); if(i == 3) printf("Programming\n"); printf("Average Score: %.2f\n",ans); printf("Number of passed students: %d\n",pnum[i]); printf("Number of failed students: %d\n",rnum-pnum[i]); printf("\n"); } printf("Overall:\n"); for(int i = 4; i >= 0; i--) { printf("Number of students who "); if(i >= 1 && i < 4) printf("passed %d or more subjects: %d\n",i,pass[i]); else if(i == 4) printf("passed all subjects: %d\n",pass[i]); else printf("failed all subjects: %d\n",rnum - pass[1]); } printf("\n"); return 0;}int main(){ // freopen("D://in.txt","r",stdin); // freopen("D://out.txt","w",stdout); while(1) { int n; init(); scanf("%d",&n); if(n == 0) break; switch (n) { case 1: add(); break; case 2: dq(); break; case 3: query(); break; case 4: ran(); break; default : sta(); } } return 0;}
0 0
- UVa12412
- Uva12412
- Uva12412 (implement)
- Uva12412 师兄帮帮忙
- 例题4-6 师兄帮帮忙 UVa12412
- 算法竞赛入门经典java版程序ch4 UVa12412
- UVa12412 - A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 师兄帮帮忙 Uva12412
- UVA12412 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)
- dijsktra+链式前向星
- XGBoost-Python完全调参指南-参数解释篇
- 【BZOJ3227】红黑树,打表找规律/DP
- IDEA中利用JUnit进行单元测试
- Lintcode 字符大小写排序
- Uva12412
- SPRING系列八之 SpringMVC原理
- PHP 解决对文件操作的高并发问题
- [APIO2012]bzoj2809 dispatching 左偏树
- React学习之扩展动画(三十)
- [kuangbin带你飞]专题八 生成树 F
- Linux基础命令
- Mac下intellij idea的go配置
- Android实现计算器布局(四种布局方式)之GridLayout网格布局