PAT B1055
来源:互联网 发布:阿里巴巴货源比淘宝贵 编辑:程序博客网 时间:2024/05/18 10:38
#include <stdio.h>#include <stdlib.h>#include <string.h>struct student{ char name[10]; int H;}Stu[10001];int cmp(const void *a,const void *b){ struct student *m=(struct student*)a; struct student *n=(struct student*)b;//此时我们定义了两个结构体指针 if(m->H==n->H)//从小到大排序 return strcmp(m->name,n->name); else return n->H-m->H;}int main(){ int num,row,i,j,k,f,right,left,count=0,re,rs,wigth,pe=1; char *tmp[10000]; scanf("%d%d",&num,&row); for(i=0;i<num;i++) { scanf("%s%d",Stu[i].name,&Stu[i].H); } qsort(Stu,num,sizeof(Stu[0]),cmp); rs=num%row;//rs为多余出来的人数。 re=num/row;//re 基础人数。 for(i=0,j=0;i<row;i++,pe=1,rs=0) { wigth=rs+re;//最后一排就是最多的人数 right=(wigth/2);//因为我们的下标是从0开始所以我们就不用加一了; left=right-1; for(k=0;k<wigth;k++) { if(pe==1) tmp[right++]=Stu[j++].name; if(pe==-1) tmp[left--]=Stu[j++].name; pe*=-1;//来回切换位置 } for (f= 0; f< wigth; f++) // 顺序输出 { printf("%s", tmp[f]); if(f<wigth-1) printf(" "); } printf("\n"); }return 0;}
0 0
- PAT B1055
- PAT B1055. 集体照
- PAT乙级练习题B1055. 集体照
- pat
- 【PAT】
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- pat
- PAT
- PAT
- PAT
- SDUT 3562 Proxy【思维+最短路SPFA】
- PAT1021_个位数统计 (15)
- VirtualBox虚拟机网络配置(NAT
- AngularJs过滤器
- NYOJ-ACM-爱摘苹果的小明
- PAT B1055
- 模板函数
- eclipse配置struts2最简单的方法
- robotframework 告警问题解决记录
- ZOJ
- http状态码是什么,有什么用,在哪里查看,分别代表什么意思?
- Integer类型
- Maximum Adverse Excursion and Maximum Favorable Excursion
- 图论(三)--深度优先搜索(DFS)