pat 1062. Talent and Virtue (25)
来源:互联网 发布:二级vb语言程序设计 编辑:程序博客网 时间:2024/06/06 02:45
难得的一次ac
题目意思直接,方法就是对virtue talent得分进行判断其归属类型,用0 1 2 3 4 表示 不合格 sage noblemen foolmen foolmen
再对序列进行排序 优先级 类型>total grade>virtue>id
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define N 100005struct node{char id[10];int v,t,c;}s[N];int cmp(const void *a,const void *b){struct node *x=(struct node *)a;struct node *y=(struct node *)b;if(x->c!=y->c)return x->c-y->c;if(y->v+y->t!=(x->v+x->t))return y->v+y->t-(x->v+x->t);if(y->v!=x->v)return y->v-x->v;return strcmp(x->id,y->id);}int main(){int n,i,l,h;while(scanf("%d%d%d",&n,&l,&h)!=EOF){for(i=0;i<n;i++){scanf("%s%d%d",s[i].id,&s[i].v,&s[i].t);if(s[i].v>=h&&s[i].t>=h)s[i].c=1;elseif(s[i].v>=h&&s[i].t>=l&&s[i].t<h)s[i].c=2;elseif(s[i].v>=l&&s[i].v<h&&s[i].t>=l&&s[i].t<h&&s[i].v>=s[i].t)s[i].c=3;elseif(s[i].v>=l&&s[i].t>=l)s[i].c=4;elses[i].c=0;}qsort(s,n,sizeof(struct node),cmp);for(i=0;i<n;i++)if(s[i].c!=0)break;printf("%d\n",n-i);for(;i<n;i++)printf("%s %d %d\n",s[i].id,s[i].v,s[i].t);}}
- 1062. Talent and Virtue (25)-PAT
- pat 1062. Talent and Virtue (25)
- 【PAT】1062. Talent and Virtue (25)
- PAT (Advanced) 1062. Talent and Virtue (25)
- PAT A 1062. Talent and Virtue (25)
- PAT 1062. Talent and Virtue (25)
- 【PAT甲级】1062. Talent and Virtue (25)
- PAT-A 1062. Talent and Virtue (25)
- PAT甲级1062. Talent and Virtue (25)
- PAT-A-1062. Talent and Virtue (25)
- 1062. Talent and Virtue (25)-PAT甲级
- PAT 甲级 1062. Talent and Virtue (25)
- PAT甲级 1062. Talent and Virtue (25)
- PAT 1062. Talent and Virtue
- PAT 1062. Talent and Virtue
- PAT--1062. Talent and Virtue
- PAT-Talent and Virtue (25)
- 1062. Talent and Virtue (25)
- 树状数组
- 深入研究Java虚拟机的类加载机制
- tomcat原理
- find command
- Linux 中断总结
- pat 1062. Talent and Virtue (25)
- Android中EditTex焦点设置和弹不弹出输入法的问题
- Statement和PreparedStatement之间的区别
- Spring分布式事务实现
- vim分屏+screen+putty
- 有关流量的那点事儿
- 常用的主机监控Shell脚本
- 黑马程序员 .NET学习笔记 <5>
- Python基础 1----Python语言基础和Python环境准备与安装