PAT乙级 1055. 集体照 (25)
2017-09-23 17:08
337 查看
//PAT-1-1057
//思路:按要求一行一行地排就行了,可以自己多写几种情况,检验下标的正确性 #include <iostream> #include <algorithm> #include <string> #include <math.h> #include <sstream> #include <vector> using namespace std; typedef struct{ string name; int height; }info; int comp(info a,info b){ if (a.height!=b.height) { return a.height>b.height; } return a.name<b.name; } int main(){ int n,k; cin>>n>>k; vector<info> s; for (int i=0; i<n; i++) { info temp; cin>>temp.name>>temp.height; s.push_back(temp); } sort(s.begin(), s.end(), comp); int per=n/k; //cout<<per<<endl; int first=per; if (per*k<n) { first++; } int count=0; for (int i=0; i<n;count++ ) { if (i==0) { if (first%2==1) { for (int j=0; j<first/2; j++) { cout<<s[2*(per/2-j)-1].name<<" "; } if (first>1) { cout<<s[0].name<<" "; } else cout<<s[0].name; for (int j=0; j<first/2; j++) { if(j!=first/2-1) cout<<s[2*(j+1)].name<<" "; else cout<<s[2*(j+1)].name; } }else{ for (int j=0; j<first/2; j++) { cout<<s[2*(first/2-j)-1].name<<" "; } for (int j=0; j<first/2; j++) { if (j!=first/2-1) { cout<<s[2*(j)].name<<" "; } else cout<<s[2*(j)].name; } } i+=first; cout<<endl; }else{ if (per%2==1) { for (int j=0; j<per/2; j++) { // cout<<count<<endl; cout<<s[2*(per/2-j)-1+first+(count-1)*per].name<<" "; } if (per>1) { cout<<s[first+(count-1)*per].name<<" "; }else cout<<s[first+(count-1)*per].name; for (int j=0; j<per/2; j++) { if(j!=per/2-1) cout<<s[2*(j+1)+first+(count-1)*per].name<<" "; else cout<<s[2*(j+1)+first+(count-1)*per].name; } }else{ for (int j=0; j<per/2; j++) { cout<<s[2*(per/2-j)-1+first+(count-1)*per].name<<" "; } for (int j=0; j<per/2; j++) { if(j!=per/2-1) cout<<s[2*(j)+first+(count-1)*per].name<<" "; else cout<<s[2*(j)+first+(count-1)*per].name; } } i+=per; cout<<endl; } } return 0; }
相关文章推荐
- pat 乙级 1055. 集体照 (25)
- [PAT乙级]1055. 集体照 (25)
- PAT乙级 1055. 集体照 (25) 结构体字符串字典排序,双端队列
- PAT-乙级-1055. 集体照 (25)
- 1055. 集体照 (25)-PAT乙级真题
- PAT乙级—1055. 集体照 (25)-native
- PAT乙级 1055. 集体照 (25)
- 乙级 PAT 1055. 集体照 (25)
- 1055. 集体照 (25) PAT乙级真题
- 1055. 集体照 (25)PAT乙级&&1109. Group Photo (25) PAT 甲级
- PAT Basic 1055. 集体照 (25)(C语言实现)
- PAT乙级1055. 集体照(25)
- PAT乙级 1055.集体照
- PAT乙级1055. 集体照 (25)
- 1055. 集体照 (25) PAT
- PAT 1055. 集体照 (25)
- PAT乙级1055 集体照
- PAT乙级1055. 集体照 (25)
- [PAT-乙级]1055.集体照
- C++ - PAT - 1055. 集体照 (25)