-
Notifications
You must be signed in to change notification settings - Fork 0
/
1055_photo.cpp
88 lines (84 loc) · 1.74 KB
/
1055_photo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include<iostream>
using namespace std;
typedef struct people
{
string name;
int height;
}Peo;
bool compare(Peo x,Peo y)
{
if(x.height==y.height)
{
return x.name<y.name;
}
else
{
return x.height>y.height;
}
}
int main()
{
int peo_num,line_num;
cin>>peo_num>>line_num;
int peer_num =peo_num/line_num;
Peo src[peo_num];
for(int i=0;i<peo_num;i++)
{
cin>>src[i].name>>src[i].height;
}
sort(&src[0],&src[peo_num],compare);
Peo * ptr=src;
int last=peer_num +peo_num%line_num;
Peo last_line[last];
Peo peer_line[peer_num];
Peo * d_ptr=&(last_line[last/2]);
Peo * p_ptr;
for(int i = 0;i<last;i++)
{
if(i%2==0)
{
d_ptr +=i;
d_ptr->name=ptr->name;
d_ptr->height=ptr->height;
}
else
{
d_ptr -=i;
d_ptr->name=ptr->name;
d_ptr->height=ptr->height;
}
ptr++;
}
for(int i=0;i<last-1;i++)
{
cout<<last_line[i].name<<" ";
}
cout<<last_line[last-1].name;
cout<<endl;
for(int i=0;i<(line_num-1);i++)
{
p_ptr = &(peer_line[peer_num/2]);
for(int j=0;j<peer_num;j++)
{
if(j%2==0)
{
p_ptr +=j;
p_ptr->name=ptr->name;
p_ptr->height=ptr->height;
}
else
{
p_ptr -=j;
p_ptr->name=ptr->name;
p_ptr->height=ptr->height;
}
ptr++;
}
for(int i=0;i<peer_num-1;i++)
{
cout<<peer_line[i].name<<" ";
}
cout<<peer_line[peer_num-1].name;
cout<<endl;
}
}