結果
問題 | No.267 トランプソート |
ユーザー |
![]() |
提出日時 | 2016-09-16 22:54:36 |
言語 | Fortran (gFortran 14.2.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 1,977 bytes |
コンパイル時間 | 263 ms |
コンパイル使用メモリ | 36,068 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 08:06:08 |
合計ジャッジ時間 | 1,028 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
program mainimplicit noneinteger::N,icharacter*2,allocatable::cards(:)integer,allocatable::x(:),y(:)read *,Nallocate(cards(N),x(N),y(N))read *,cardsdo i=1,Nx(i) = mark2num(cards(i))end doy = qsort(x)do i=1,Ncards(i) = num2mark(y(i))end dodo i=1,N-1write(*, '(a," ")',advance='no') cards(i)end doprint '(a)',cards(N)containsfunction mark2num(c) result(num)character*2::cinteger::numnum = 0select case(ICHAR(c(1:1)))case (ICHAR('D'))num = numcase (ICHAR('C'))num = num + 14case (ICHAR('H'))num = num + 28case (ICHAR('S'))num = num + 42end selectselect case(ICHAR(c(2:2)))case (ICHAR('A'))num = num + 1case (ICHAR('T'))num = num + 10case (ICHAR('J'))num = num + 11case (ICHAR('Q'))num = num + 12case (ICHAR('K'))num = num + 13case defaultnum = num + (ICHAR(c(2:2))-ICHAR('0'))end selectend function mark2numfunction num2mark(num) result(c)character*2::cinteger::numselect case(num/14)case (0)c(1:1) = 'D'case (1)c(1:1) = 'C'case (2)c(1:1) = 'H'case (3)c(1:1) = 'S'end selectselect case(MOD(num,14))case (1)c(2:2) = 'A'case (10)c(2:2) = 'T'case (11)c(2:2) = 'J'case (12)c(2:2) = 'Q'case (13)c(2:2) = 'K'case defaultc(2:2) = CHAR(ICHAR('0')+MOD(num,14))end selectend function num2markrecursive function qsort(x) result(y)integer,intent(in) ::x(:)integer,allocatable::y(:)integer::pivot,totaltotal = size(x)if (total <=1) theny = xelsepivot = x(total/2)y = [qsort(pack(x, x .lt. pivot)), &pack(x, x .eq. pivot), &qsort(pack(x, x .gt. pivot))]endifend function qsortend program main