CC BY 4.0 (除特别声明或转载文章外)
如果这篇博客帮助到你,可以请我喝一杯咖啡~
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
{-
文件bids_201711.txt 是广州市某月车牌竞价信息,包含若干行,每行形如「1234198004118085 29570」,表示一位竞价人的身份证号和出价。
假设本月有10个车牌竞拍。你的任务是统计相关信息,包括最高成交价、最低成交价、平均成交价、按照出价从高到低列车前十位出价人身份证号和出价,并存入另一个文件bidResults.txt中。例如,统计结果可能如文件bidResults1.txt 所示。
要求:
1. 提交你的代码文件;
2. 提交统计结果文件,或者将结果粘贴在提交窗口。
提示:需要排序函数,请hoogle :: [a] -> [a],或者自定义排序。
-}
--代码写的太丑了,以后重写吧……
import Data.Char
import System.IO
import Text.Printf
main::IO()
main= do
txt<-readFile "bids_201711.txt"
let dat=lines txt
let mi=getmin dat
let ma=getmax dat
let sum=getsum dat
let len=length dat
let aftersort=getsort dat
writeFile "bidResults.txt"
(printf "最高成交价:%d\n最低成交价:%d\n平均成交价:%d\n总共有%d参与竞价成交名单:\n%s"
ma mi (div sum len) len (unlines (take 10 aftersort)))
digit::String->Int->Int
digit s n=(ord (s!!n))-(ord '0')
getval::String->Int
getval s=(digit s 23)*10000+(digit s 24)*1000+(digit s 25)*100+(digit s 26)*10+(digit s 27)
getmin::[String]->Int
getmin [a]=getval a
getmin (x:xs)=if a<b then a else b
where
a=getmin [x]
b=getmin xs
getmax::[String]->Int
getmax [a]=getval a
getmax (x:xs)=if a>b then a else b
where
a=getmax [x]
b=getmax xs
getsum::[String]->Int
getsum [a]=getval a
getsum (x:xs)=(getmax [x])+(getmax xs)
getsort::[String]->[String]
getsort []=[]
getsort (x:xs)=(getsort [y|y<-xs,(getval y)>(getval x)])++[x]++(getsort [y|y<-xs,(getval y)<(getval x)])
下面是bidResults.txt
的内容。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
最高成交价:29995
最低成交价:10008
平均成交价:111
总共有491参与竞价成交名单:
1234198610248103 29995
1535198004062143 29948
1334197907229015 29922
1435198110019109 29916
1535198412072052 29822
1533198811246245 29820
1633197706227256 29815
1234198205229019 29799
1533198710186071 29777
1536198405206083 29727
下面是bids_201711.txt
的内容。
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
1230197812061080 24596
1230197210049047 11293
1331197708184092 26387
1331198509014173 21991
1331198702174176 13778
1333197808181338 29686
1333197812025146 27955
1333198709276233 12495
1334197907229015 29922
1334197205049158 10416
1430198708181002 25186
1430197102201027 24090
1430197912121030 19367
1431198402182064 11682
1431197303143010 20660
1431197711224092 13196
1431197512184190 12069
1432197703132181 28424
1433197902071057 11985
1433198810041098 18754
1433198111221148 25994
1433197311121198 25065
1433197711041206 21115
1433197412131354 13146
1434199006226012 17399
1434198808016016 25430
1434198112246017 26006
1434197106257001 12193
1434199012017087 22698
1434198612107099 27705
1434197910097116 20944
1434198205257149 23445
1434197105058037 14507
1434197511068057 23953
1434197410198061 15966
1434199001168083 21456
1434197712158085 25448
1434198912018117 20420
1434198807048125 25469
1435198609050022 12447
1435198409016106 23101
1435198110019109 29916
1436198306186113 10806
1436197501287048 13904
1530198810111127 16078
1530199002261200 15993
1530198304086034 26630
1530198411268038 14159
1530197408019037 21750
1530199002079054 10057
1531198401270053 24736
1531198101252040 26514
1531198110182065 12418
1531197704223007 13175
1531198708234191 25275
1532198206021061 12352
1532197309044084 21131
1532198206094108 20076
1533198402091046 16392
1533197405231092 25507
1533197510141097 13482
1533199006061403 22390
1533197905261404 22059
1533198303111443 25906
1533198508036001 18009
1533197512086002 27627
1533197906156007 25881
1533197504206011 13898
1533198007276012 27095
1533198004256027 27761
1533197606026083 18785
1533197702066114 18618
1533197910176205 12649
1533198811246245 29820
1534198403103001 25702
1534198403183043 18033
1534197007193054 28238
1534199004133073 22004
1534198701103076 26811
1534198606093104 12159
1534199008033108 19285
1534197412013119 21302
1534198610178012 11210
1534198406018015 22246
1534198507278026 19547
1534198702279031 22679
1534198002219036 29597
1534198605189050 11796
1534198007209121 19654
1535198702061054 25342
1535198212101059 22819
1535197503131117 19377
1535198803255119 22937
1535197608028311 15710
1535197501128369 24591
1536197405270013 15526
1536198402134004 18326
1536197312034015 21755
1536197901275016 29158
1536198405206083 29727
1234199004029001 14620
1234198002169002 12831
1234198611199003 13283
1234198012199004 12402
1234198706219005 24886
1234197812129006 23230
1234197701239007 19611
1234197906209008 13897
1234197304129009 10231
1234197003259010 24607
1234198701079011 29518
1234198405169012 21416
1234198610119013 24790
1234198907069014 13158
1234198405109015 22260
1234198106179016 24818
1234198107099017 24940
1234197708199018 16961
1234198708199019 15929
1234198201239020 18482
1234198207069021 13467
1234197312119022 22046
1234198912069023 29357
1234198311129024 13816
1234198811099025 22464
1234197104079026 10351
1234197512268070 26906
1234197504178071 18504
1234197301168073 25673
1234198605098074 16561
1234198509118075 23956
1234197511198076 15831
1234198302028077 26572
1234198708238078 23611
1234197312088079 28083
1234197406148080 14268
1234197703048081 11723
1234198001208082 20541
1234198510168083 20543
1234197608078084 22597
1234199001118085 25643
1234198203158086 16879
1234197110178087 25850
1234199003188088 27679
1234197405268089 10967
1234197311178090 10646
1234198204058091 24014
1234198603198092 13800
1234199012078093 26813
1234197006098094 11138
1234197108058095 24278
1234198505268096 23281
1234197809078097 17968
1234198012038098 22295
1234198508078099 16772
1234197907098100 20025
1234197707098101 11314
1234198808118102 27658
1234198610248103 29995
1234197409128104 27286
1234197303158105 20618
1234198311088106 27155
1234198701048107 28656
1234198304078108 13494
1234198401198109 10978
1234197611088110 21760
1234198602148111 11563
1234198311048112 22574
1234197701268113 12725
1234198802128114 26076
1234197303028115 26401
1234197509058116 28388
1234198410288117 27558
1234199007158118 16683
1234197510248119 15552
1234197208068120 13256
1234197201068121 20977
1234197712098122 13404
1234197912258123 21381
1234197307058124 27165
1234197811128125 25232
1234197003078126 23424
1234197907048127 21859
1234197807218128 26843
1234197303148130 16550
1234198609288131 18064
1234198501128132 23214
1234197005068133 14521
1234197508028134 12830
1234198402278135 11977
1234197504218136 28962
1234197709228137 13377
1234198107108138 26220
1230197405203218 26698
1233197007050058 24942
1233198104060178 21090
1233198811040364 27434
1233197412030414 11319
1236198803025088 12697
1234197906138139 28617
1234198102238140 20104
1234198709218141 14266
1234198503118142 25458
1234198207178143 12879
1234197612018144 25047
1234197702038145 12443
1234197107148146 26526
1234198710258147 27844
1234198103128148 21973
1234197207278149 29673
1234197310038150 25735
1234197512218151 22471
1234197211258152 11752
1234199004238153 28643
1234198009078154 27158
1234198911248155 10311
1234198611138156 16654
1234197808048157 24494
1234197510278158 21539
1234197506208159 13743
1234197309158160 12802
1234198505258161 12126
1234198302098162 10694
1234197710248163 12944
1234198610148164 12065
1234197005198165 10008
1234197404238166 10634
1234198007278167 21425
1234197001168168 22861
1234197303168169 27418
1234197307178170 22362
1234197905168171 19947
1234197903208172 11690
1234198106068173 11265
1234198904278174 10389
1234198903268175 26515
1234197304078176 17138
1234197402198177 18844
1234197207068178 20639
1234198205098179 16327
1234198902268180 27563
1234198102138181 10179
1131198902092008 27936
1131197304108030 28446
1233198109040089 17461
1233198508200203 10012
1235197601273174 12751
1235198209173224 23275
1235198609203285 22081
1236197907235026 16804
1234198801289001 27786
1234199006189002 19019
1234197205039003 28672
1234198810089004 15417
1234197703039005 24318
1234197409279006 19974
1234199002139007 27919
1234197506069008 11759
1234197205049009 16736
1234198002269010 17838
1234198402049011 13050
1234199006149012 28597
1234198503069013 22384
1234199004229014 10673
1234198903089015 11229
1234198711169016 23558
1234197910059017 16595
1234198402219018 17832
1234198205229019 29799
1234197411019020 25989
1234198410169021 18688
1234197905169022 18017
1234198507059023 11564
1234198002149024 18723
1234198303269025 14515
1234199005239026 14559
1330198201289011 20717
1331198702114240 23112
1332198107013008 11228
1431198511154103 24890
1432198409062084 22022
1432197202204037 13256
1433198009085060 23635
1433198709255216 14348
1434197611098044 12396
1434197504148184 21570
1435197411122073 11990
1435198202033142 11009
1435198406073430 27399
1530197111248009 10433
1530199005108029 24867
1530197411288030 26199
1530198312158054 24154
1531198209102002 14123
1531197802104121 18770
1531197002204204 23400
1533198607241042 13904
1533197706121311 13904
1533198407216057 29164
1533197507106058 20537
1533198710186071 29777
1533198307256264 27122
1533199004286269 19516
1534197908203047 15104
1534199009228014 19371
1534198602109107 12243
1534197608149108 10478
1535198607190037 12904
1535198704112045 25296
1535197511282065 22632
1535197707192081 12537
1535197602022083 11064
1535198407222087 15885
1535198002172088 28172
1535198802082089 24058
1535198909192091 12171
1535199012282144 22735
1535199008232161 25474
1535198603242229 24408
1535198503042296 26162
1535197811082354 26763
1535198609192434 17675
1535198808143011 28201
1536198105154006 27690
1630197409082111 24052
1630198811038030 25783
1630198205108032 27212
1630198603098044 26489
1630199008068110 28112
1630197410128114 19099
1630198607238144 22138
1630199006139005 14612
1631198907150001 19596
1631197601170011 18218
1631198401250022 15989
1631199003230055 17874
1631198711140072 24781
1631198203040077 28717
1631197809172009 16202
1631198708074019 11821
1631197202127017 14173
1631199008057090 20210
1631198001288124 19047
1631197802238243 12079
1631198709038263 20999
1631198508158280 26914
1632198506218013 24126
1632198707018035 10931
1633198412267019 26385
1633198611277075 19148
1633198101057101 25844
1633197504057210 12773
1633197307177216 11246
1633197202067229 17580
1633197706227256 29815
1633198908247269 19364
1633197607047270 27994
1633197310259025 17967
1633198004039028 16854
1633198805169035 16606
1633198707129053 16645
1634197601010006 17806
1634197906140030 27674
1634198202280069 18967
1634197202120078 18059
1634197606150098 19578
1634197501180121 23982
1634197501210147 28722
1634198406230150 16101
1634197304190152 15267
1634198707190170 12856
1634197409120218 15195
1635197407271010 27869
1636198202023012 29285
1636198112105041 15066
1636198811265174 19174
1535198109102012 15411
1535199008052069 25931
1535197407192001 16598
1535198509162002 16051
1535198009242004 10939
1535199003172005 11552
1535197510072006 14208
1535197405222007 16981
1535198412282008 23446
1535197511042009 14307
1535198404182010 11877
1535197812232011 14899
1535198403162013 26055
1535197012092014 15800
1535197612022015 16039
1535197104142016 19642
1535198905182017 13293
1535197610112018 25428
1535197502022019 27111
1535198904032020 25213
1535198111102021 28999
1535198310102022 13916
1535198112272023 17217
1535197208162047 11613
1535198406272048 13450
1535197312272049 21779
1535197902132050 10635
1535197106262051 18108
1535198412072052 29822
1535197408102053 23618
1535198402212054 18687
1535199012262055 28832
1535197408082056 11569
1535198206132057 25421
1535198604132058 22643
1535198904032059 29229
1535198101022060 26379
1535197002222061 14390
1535197902082062 22243
1535198903102063 22734
1535198808062064 18847
1535197203162065 16216
1535198507172066 17110
1535197509042067 18021
1535198612162068 24746
1535198203182093 18266
1535198010192094 16164
1535197607212095 15046
1535198404092096 25556
1535198108172097 18403
1535198308012098 12940
1535197510222099 29560
1535197512162100 17683
1535198805042101 12112
1535198807282102 23389
1535198310102103 11622
1535198407272104 11065
1535197507192105 15675
1535198503152106 15769
1535198307062107 20625
1535198106262108 29649
1535197903262109 28689
1535198204132110 13639
1535198808202111 27614
1535197603152112 18166
1535198612242113 12361
1535197010172114 17072
1535198802232115 15397
1535198301082139 13214
1535198202242140 18728
1535199002222141 16027
1535197208212142 28702
1535198004062143 29948
1535197005102144 16407
1535197301202145 18538
1535198407192146 11567
1535198012082147 23755
1535198007192148 19494
1535197812202149 14265
1535198803082150 22251
1535197904252151 20512
1535197709052152 21623
1535197106102153 14812
1535198906052154 20807
1535198702182155 12771
1535198606092156 22696
1535198905172157 25593
1535197807262158 27720
1535197911262159 24090
1535197204142160 13328
1535198004112161 14277
1535197106272186 27998
1535197306042188 12492
1535198512242189 15235
1535198308152190 20690
1535198106072191 19163
1535198903072192 16872
1535198811022193 15760
1535198301262194 15536
1535198801212195 12584
1535198908052197 13597
1535198901142198 29418
1535199004132199 16650
1535197411172200 29393
1535198309082201 23186
1535197508192202 10021
1535198911232203 15774
1535197808032204 17627
1535197812152205 28673
1535197204162206 27991
1535198808112207 18116
1535197411142208 29056
1535197409232003 14656
1535197012152187 11778
1535198107162196 17291