forked from mohitsh/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsbank.cpp
203 lines (203 loc) · 3.7 KB
/
sbank.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// 2008-01-30
#include <stdio.h>
struct number
{
int control;
int bank;
int owner1;
int owner2;
int owner3;
int owner4;
};
inline bool operator>(const number& n1,const number& n2)
{
if (n1.control<n2.control)
return false;
if (n1.control>n2.control)
return true;
if (n1.bank<n2.bank)
return false;
if (n1.bank>n2.bank)
return true;
if (n1.owner1<n2.owner1)
return false;
if (n1.owner1>n2.owner1)
return true;
if (n1.owner2<n2.owner2)
return false;
if (n1.owner2>n2.owner2)
return true;
if (n1.owner3<n2.owner3)
return false;
if (n1.owner3>n2.owner3)
return true;
if (n1.owner4<n2.owner4)
return false;
if (n1.owner4>n2.owner4)
return true;
return false;
}
inline bool operator>=(const number& n1,const number& n2)
{
if (n1.control<n2.control)
return false;
if (n1.control>n2.control)
return true;
if (n1.bank<n2.bank)
return false;
if (n1.bank>n2.bank)
return true;
if (n1.owner1<n2.owner1)
return false;
if (n1.owner1>n2.owner1)
return true;
if (n1.owner2<n2.owner2)
return false;
if (n1.owner2>n2.owner2)
return true;
if (n1.owner3<n2.owner3)
return false;
if (n1.owner3>n2.owner3)
return true;
if (n1.owner4<n2.owner4)
return false;
if (n1.owner4>n2.owner4)
return true;
return true;
}
inline bool operator<=(const number& n1,const number& n2)
{
if (n1.control<n2.control)
return true;
if (n1.control>n2.control)
return false;
if (n1.bank<n2.bank)
return true;
if (n1.bank>n2.bank)
return false;
if (n1.owner1<n2.owner1)
return true;
if (n1.owner1>n2.owner1)
return false;
if (n1.owner2<n2.owner2)
return true;
if (n1.owner2>n2.owner2)
return false;
if (n1.owner3<n2.owner3)
return true;
if (n1.owner3>n2.owner3)
return false;
if (n1.owner4<n2.owner4)
return true;
if (n1.owner4>n2.owner4)
return false;
return true;
}
/*inline number& operator=(const number& n)
{
number N;
N.bank=n.bank;
N.control=n.control;
N.owner1=n.owner1;
N.owner2=n.owner2;
N.owner3=n.owner3;
N.owner4=n.owner4;
return N;
}*/
inline bool operator==(const number& n1,const number& n2)
{
if (n1.bank!=n2.bank) return false;
if (n1.control!=n2.control) return false;
if (n1.owner1!=n2.owner1) return false;
if (n1.owner2!=n2.owner2) return false;
if (n1.owner3!=n2.owner3) return false;
if (n1.owner4!=n2.owner4) return false;
return true;
}
void quicksort(number a[],int l,int u)
{
number t;
if (u-l<=0)
return;
if (u-l==1)
{
if (a[l]>a[u])
{
t=a[u];
a[u]=a[l];
a[l]=t;
}
return;
}
number key=a[l];
int L=l;
int R=u;
do
{
while ((R>L)&&(a[R]>=key))
R--;
if (R==L) break;
a[L]=a[R];
while ((R>L)&&(a[L]<=key))
L++;
if (R==L) break;
a[R]=a[L];
}
while (true);
a[L]=key;
if (L-l>1)
quicksort(a,l,L-1);
if (u-R>1)
quicksort(a,R+1,u);
}
int main()
{
int i,j,t,m,n;
char c[32];
static number a[100000];
#ifdef DEBUG
FILE* f=fopen("SBANK.in","r");
fscanf(f,"%d",&t);
#else
scanf("%d",&t);
#endif
for (i=0; i<t; i++)
{
if (i>0) putchar('\n');
#ifdef DEBUG
fscanf(f,"%d",&n);
#else
scanf("%d",&n);
#endif
for (j=0; j<n; j++)
#ifdef DEBUG
fscanf(f,"%d %d %d %d %d %d",&a[j].control,&a[j].bank,
&a[j].owner1,&a[j].owner2,&a[j].owner3,&a[j].owner4);
#else
scanf("%d %d %d %d %d %d",&a[j].control,&a[j].bank,
&a[j].owner1,&a[j].owner2,&a[j].owner3,&a[j].owner4);
#endif
quicksort(a,0,n-1);
int k;
for (j=0; j<n;)
{
k=j;
do
k++;
while ((k<n)&&(a[k]==a[j]));
c[0]=0;
sprintf(c,"%2d_%8d_%4d_%4d_%4d_%4d",a[j].control,a[j].bank,
a[j].owner1,a[j].owner2,a[j].owner3,a[j].owner4);
for (m=0; m<31; m++)
if (c[m]==' ')
putchar('0');
else if (c[m]=='_')
putchar(' ');
else
putchar(c[m]);
printf(" %d\n",k-j);
j=k;
}
}
return 0;
}