PTA Basic Level 1055
2021/8/6 23:06:43
本文主要是介绍PTA Basic Level 1055,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#include<bits/stdc++.h> using namespace std; typedef struct{ char name[9]; int height; }stu; int cmp(const void* a,const void* b){ stu m=*(stu *)a; stu n=*(stu *)b; if (m.height==n.height) return strcmp(m.name,n.name); else return n.height-m.height; } int main(){ int n,k,r=1,index=0; cin>>n>>k; stu a[n]; for (int i=0;i<n;i++){ scanf("%s %d",a[i].name,&a[i].height); } qsort(a,n,sizeof(stu),cmp); // cout<<"---------------------------------------"<<endl; // cout<<"排序后"<<endl; // for (int i=0;i<n;i++){ // printf("%s %d\n",a[i].name,a[i].height); // } // cout<<"---------------------------------------"<<endl; while (r<=k){ int cnt_people;//代表该行的人数 if (r==1) cnt_people=n-n/k*(k-1); else cnt_people=n/k; int middle=cnt_people/2+1;//代表中间位置 stu ans[cnt_people]; ans[middle-1]=a[index]; int temp=index+1; for (int i=middle-2;i>=0;i--){//先填左边的 ans[i]=a[temp]; temp+=2; } temp=index+2; for (int i=middle;i<cnt_people;i++){//再填右边的 ans[i]=a[temp]; temp+=2; } for (int i=0;i<cnt_people;i++){ if (i!=0) printf(" "); printf("%s",ans[i].name); } index+=cnt_people; if (r!=k) cout<<endl; r++; } return 0; }
这篇关于PTA Basic Level 1055的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-28pyqt 怎么打包整个项目-icode9专业技术文章分享
- 2024-09-28laravel Commands 创建带有参数的 Artisan 命令的步骤和示例-icode9专业技术文章分享
- 2024-09-28antd怎么实现渲染tiff图片-icode9专业技术文章分享
- 2024-09-28英文半角中划线和中文全角的中划线有什么区别-icode9专业技术文章分享
- 2024-09-28nvm npm 和node 他们之间有什么关系-icode9专业技术文章分享
- 2024-09-28Node Version Manager (nvm)使用教程-icode9专业技术文章分享
- 2024-09-28nvm命令太慢,是什么原因-icode9专业技术文章分享
- 2024-09-28Kotlin 如何增加、删除和修改 MutableStateFlow 中的值。-icode9专业技术文章分享
- 2024-09-28Kotlin的stateFlow.update 写法介绍-icode9专业技术文章分享
- 2024-09-28kotlin 怎么获取当前时间格式-icode9专业技术文章分享