MaxMinSwap

Submit

Your name:
File:
Open code-statistics:

Language is selected by the extension of the file. See the list of supported languages to know the extension of your language.

Problem

You receive a list of positive integers.
Find the biggest and smallest number in the list and
swap them. Then find the nth biggest and nth smallest
number and swap them too.

E.g

[9,1,2,3,4,0] - max 9, min 0
[0,1,2,3,4,9] - max2nd 4, min2nd 1
[0,4,2,3,1,9] - max3rd 3, min3rd 2
[0,4,3,2,1,9] - finished

-- mroman

Options

exec is denied

now post-mortem time, all source codes will be revealed

Sample input:_

[2,36,29,83]
[30,81,55,15,68,26,71,29,6,46]
[16,66,42,76,59]
[65,47,65,47,74,33,41,38,75,59]
[64,55,39,26,33,66]
[46,50,89,82,53,27,51,32]
[77,83,14,65,58,39]
[87,36,42,85]
[82,13,68,55]
[42,65,81,17,46,21,46,30,43,71,60]
[52,45,18,30]
[76,64,60,54,86,78,81,15]
[40,12,56,37,49,78,83,40,40,59]
[69,77,53,16,35,42,54,48,70]
[8,65,60,40,12,88,67]
[12,45,3,9,83]
[25,53,16,38,30,79]
[21,57,88,34,20,53,23]
[33,23,34,64,85,41,39,84,42]
[85,56,49,38]
[37,34,68,87,2]
[12,23,47,51,24,27]
[79,89,80,42,45,57,75]
[45,86,39,40,89,56,75,53,26]
[62,30,51,13,46,26,4,56]
[76,42,77,10,53,75,46]
[7,27,26,48,59,37,7,58]
[1,19,49,64,18,74,57,2,16,28,43]
[56,11,25,37,68,49,32,65]
[13,16,37,43,1,70]
[50,84,90,86]
[52,69,72,4,62,85,30]
[79,47,71,58,62,22]
[77,24,44,80,8,82,73,84,61]
[51,9,74,13,55,42,59]
[37,46,82,34,48,66,28,81]
[48,48,34,73,36,61,14,27,44,89,36]
[41,83,19,23,83,75,2,86,88,9,29]
[88,21,38,39,27,41,25,75]
[17,57,61,2,76,8]
[68,28,22,57,77]
[24,11,23,75,6,47,34]
[45,50,65,37,21,12]
[11,67,72,23,30,54,75]
[58,4,45,16,18,58,50,89,6]
[82,26,9,14,74,70,89,21,77,25,19]
[64,34,50,61,72,12,89,59,16]
[67,80,52,52]
[20,9,30,4,84,27,31,74]
[83,5,23,63,74,7,68]
[45,55,29,49,69,46,18]
[41,31,17,14,63,62,3]
[37,21,83,7,17,89,78]
[78,77,76,89,40]
[1,70,11,74,88,80,90,4,21]
[32,44,87,61,6,77,16,25]
[11,6,55,86,74,41,23,36]
[17,35,51,20,20]
[41,74,36,54,86,3,33]
[66,84,64,45,31,19,73]
[66,85,83,24]
[76,58,26,34,84,21]
[19,52,14,68]
[29,6,74,36,12,13]
[66,10,36,24,31,75,48,20,88]
[1,86,22,44,31,67,46,80,60]
[13,34,12,70,10]
[80,13,74,78,2,12,4,19]
[37,70,19,44,2,19]
[30,82,27,67,7,70,75]
[69,3,11,12,45,29,72,29]
[70,84,4,49,75,61,68,42]
[31,47,88,18,48,5,32,57]
[55,77,33,32,77]
[22,55,23,50,71,60,30,88]
[53,54,37,59,88,80,60]
[68,43,70,13,7,58,54]
[34,84,4,21,7,34]
[73,75,14,2,8,25,15,5,86,79]
[50,56,69,30,84]
[43,56,26,25,21]
[74,19,55,39,55,17,16,80,24]
[75,55,37,81,47,27,27,30,2]
[19,71,34,50,83,85]
[71,70,13,3]
[19,81,4,77,9,35]
[34,82,31,60,37,54,76,18,43,24]
[83,55,51,50,12,29,31,62]
[45,4,50,50,16,55,63]
[3,19,43,31,28,85]
[31,44,41,8,6,28,63]
[73,9,25,12,6,59,10,56,49]
[75,25,83,16,36]
[44,50,19,30,32,55,42,83,66,83,77]
[68,20,78,1,28,64,48,20]
[7,46,53,51,48,53,82]
[57,33,86,80,40,4,57,63,37]
[37,15,55,29,24,2,2]
[27,55,75,31,72,81]
[11,24,11,71,62,43]
[62,15,52,7,36,43,81,70]
[7,72,68,78,64]
[15,89,23,22,45,52,56]
[43,29,73,70,30,20]
[73,32,80,55,57]
[18,60,1,22,28,12]
[36,74,74,16]
[10,34,76,27,36,53,68,6,28,29]
[78,82,7,66,44]
[58,1,27,13,29,36,44,38,13]
[17,38,24,39,49,86]
[88,79,33,58,46]
[63,81,82,35,81,26]
[81,56,6,86,46,18,9,12,84]
[59,14,27,46,66,4,22,43,28]
[61,72,67,46,77,55,67]
[83,68,43,47,61]
[84,5,89,44,16,68,5,35,76]
[2,53,68,19,43]
[30,56,70,74,83]
[57,72,87,82,31,29,50,61]
[62,74,26,45]
[34,85,44,63,14,35]
[77,33,18,2,9,71]
[57,40,20,76,32]

Sample output:

[83,29,36,2]
[46,6,29,71,26,68,15,55,81,30]
[76,42,66,16,59]
[41,65,47,59,38,75,65,74,33,47]
[33,39,55,66,64,26]
[53,51,27,32,46,89,50,82]
[39,14,83,58,65,77]
[36,87,85,42]
[13,82,55,68]
[60,30,17,81,43,71,46,65,46,21,42]
[18,30,52,45]
[64,76,78,81,15,60,54,86]
[59,83,40,78,40,37,12,56,49,40]
[42,16,53,77,70,69,48,54,35]
[88,40,60,65,67,8,12]
[12,9,83,45,3]
[53,25,79,30,38,16]
[57,21,20,34,88,23,53]
[84,85,64,34,23,41,42,33,39]
[38,49,56,85]
[37,68,34,2,87]
[51,47,23,12,27,24]
[57,42,45,89,80,79,75]
[56,39,86,75,26,45,40,53,89]
[4,46,26,56,30,51,62,13]
[42,76,10,77,53,46,75]
[59,37,48,26,7,27,58,7]
[74,43,18,2,49,1,16,64,57,28,19]
[32,68,65,49,11,37,56,25]
[43,37,16,13,70,1]
[90,86,50,84]
[69,52,30,85,62,4,72]
[22,71,47,62,58,79]
[61,82,80,44,84,24,73,8,77]
[51,74,9,59,42,55,13]
[66,48,28,81,46,37,82,34]
[36,36,61,27,48,34,89,73,44,14,48]
[41,19,83,83,23,29,88,9,2,86,75]
[21,88,39,38,41,27,75,25]
[57,17,8,76,2,61]
[28,68,77,57,22]
[24,47,34,6,75,11,23]
[37,21,12,45,50,65]
[75,30,23,72,67,54,11]
[6,89,45,58,50,16,18,4,58]
[14,26,89,82,21,25,9,74,19,70,77]
[34,64,61,50,16,89,12,59,72]
[52,52,80,67]
[31,74,27,84,4,30,20,9]
[5,83,68,63,7,74,23]
[49,29,55,45,18,46,69]
[17,31,41,62,3,14,63]
[37,78,17,89,83,7,21]
[76,77,78,40,89]
[90,70,80,21,4,11,1,88,74]
[44,32,6,25,87,16,77,61]
[74,86,23,6,11,36,55,41]
[51,20,17,35,20]
[41,33,54,36,3,86,74]
[45,19,64,66,73,84,31]
[83,24,66,85]
[26,34,76,58,21,84]
[52,19,68,14]
[13,74,6,12,36,29]
[24,88,36,66,48,20,31,75,10]
[86,1,80,60,67,31,46,22,44]
[13,12,34,10,70]
[2,19,12,4,80,74,78,13]
[19,2,44,19,70,37]
[70,7,75,67,82,30,27]
[11,72,69,45,12,29,3,29]
[49,4,84,70,42,68,61,75]
[48,32,5,57,31,88,47,18]
[55,32,77,77,33]
[88,50,71,55,23,30,60,22]
[80,60,88,59,37,53,54]
[13,58,7,68,70,43,54]
[7,4,84,34,34,21]
[14,8,73,86,75,15,25,79,2,5]
[69,56,50,84,30]
[25,21,26,43,56]
[17,55,19,39,24,74,80,16,55]
[27,27,37,2,30,75,55,47,81]
[85,50,83,71,34,19]
[3,13,70,71]
[35,4,81,9,77,19]
[54,18,60,31,43,34,24,82,37,76]
[12,31,50,51,83,62,55,29]
[50,63,45,50,55,16,4]
[85,43,19,28,31,3]
[31,8,28,44,63,41,6]
[6,59,25,49,73,9,56,10,12]
[25,75,16,83,36]
[55,50,83,83,77,44,66,19,42,30,32]
[20,68,1,78,48,20,28,64]
[82,53,46,51,53,48,7]
[40,80,4,33,57,86,57,37,63]
[2,29,2,15,24,55,37]
[81,72,31,75,55,27]
[71,43,62,11,11,24]
[36,70,43,81,62,52,7,15]
[78,64,68,7,72]
[89,15,52,56,45,23,22]
[30,70,20,29,43,73]
[55,80,32,73,57]
[22,1,60,18,12,28]
[74,16,36,74]
[68,29,6,53,28,27,10,76,36,34]
[44,7,82,66,78]
[1,58,36,44,29,27,13,13,38]
[86,39,49,38,24,17]
[33,46,88,58,79]
[81,35,26,81,63,82]
[12,18,86,6,46,56,84,81,9]
[14,59,43,22,4,66,46,27,28]
[67,55,61,77,46,72,67]
[43,47,83,68,61]
[5,89,5,44,76,35,84,68,16]
[68,19,2,53,43]
[83,74,70,56,30]
[61,50,29,31,82,87,72,57]
[45,26,74,62]
[63,14,35,34,85,44]
[2,18,33,77,71,9]
[32,40,76,20,57]

Ranking

Ruby _

RankUserSizeTimeDateStatistics
1leonid920.01772012/08/02 03:30:150B / 48B / 38B
2clock1120.03192012/08/01 16:02:130B / 58B / 51B

Perl _

RankUserSizeTimeDateStatistics
1tybalt89780.07292012/08/03 12:18:380B / ?B / ?B

Python _

RankUserSizeTimeDateStatistics
1leonid1050.05962012/08/02 02:58:550B / ?B / ?B
2hallvabo1320.03692012/08/01 08:10:550B / 62B / 59B

J _

RankUserSizeTimeDateStatistics
1I., S.780.06262012/08/01 23:21:130B / 16B / 62B
2I., S.630.04592012/08/17 19:56:220B / 11B / 52B

GolfScript _

RankUserSizeTimeDateStatistics
1tails620.52642012/08/01 23:25:280B / 9B / 53B

Language Ranking_

RankLangUserSizeScore
1GolfScripttails6210000
2JI., S.639841
3Perltybalt89787948
4Rubyleonid926739
5Pythonleonid1055904

return top