結果

問題 No.267 トランプソート
ユーザー jjjj
提出日時 2016-09-16 22:54:36
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,977 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 30,904 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-10 22:11:43
合計ジャッジ時間 1,361 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

program main
  implicit none
  integer::N,i
  character*2,allocatable::cards(:)
  integer,allocatable::x(:),y(:)
  read *,N
  allocate(cards(N),x(N),y(N))
  read *,cards
  do i=1,N
     x(i) = mark2num(cards(i))
  end do
  y = qsort(x)
  do i=1,N
     cards(i) = num2mark(y(i))
  end do

  do i=1,N-1
     write(*, '(a," ")',advance='no') cards(i)
  end do
  print '(a)',cards(N)
contains
  function mark2num(c) result(num)
    character*2::c
    integer::num
    num = 0
    select case(ICHAR(c(1:1)))
    case (ICHAR('D'))
       num = num
    case (ICHAR('C'))
       num = num + 14
    case (ICHAR('H'))
       num = num + 28
    case (ICHAR('S'))
       num = num + 42
    end select

    select case(ICHAR(c(2:2)))
    case (ICHAR('A'))
       num = num + 1
    case (ICHAR('T'))
       num = num + 10
    case (ICHAR('J'))
       num = num + 11
    case (ICHAR('Q'))
       num = num + 12
    case (ICHAR('K'))
       num = num + 13
    case default
       num = num + (ICHAR(c(2:2))-ICHAR('0'))
    end select
  end function mark2num
  function num2mark(num) result(c)
    character*2::c
    integer::num
    select 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 select
    select 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 default
       c(2:2) = CHAR(ICHAR('0')+MOD(num,14))
    end select
  end function num2mark
  recursive function qsort(x) result(y)
    integer,intent(in) ::x(:)
    integer,allocatable::y(:)
    integer::pivot,total
    total = size(x)
    if (total <=1) then
       y = x
    else
       pivot = x(total/2)
       y = [qsort(pack(x, x .lt. pivot)), &
            pack(x, x .eq. pivot),        &
            qsort(pack(x, x .gt. pivot))]
    endif
  end function qsort
end program main
0