結果
| 問題 |
No.267 トランプソート
|
| コンテスト | |
| ユーザー |
jj
|
| 提出日時 | 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 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
jj