結果
| 問題 |
No.297 カードの数式
|
| コンテスト | |
| ユーザー |
jj
|
| 提出日時 | 2017-01-08 09:06:31 |
| 言語 | Fortran (gFortran 14.2.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,775 bytes |
| コンパイル時間 | 184 ms |
| コンパイル使用メモリ | 33,144 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-17 17:57:18 |
| 合計ジャッジ時間 | 905 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 14 |
ソースコード
program main
implicit none
integer::N,i
character::c(15)
integer::num(0:9),num2(0:9),plus,minus,char
integer::minvalue,maxvalue
data num/10*0/,plus/0/,minus/0/,minvalue/0/,maxvalue/0/
read *,N
read *,c(1:N)
do i=1,N
if(c(i).eq.'+') then
plus = plus + 1
else if(c(i).eq.'-') then
minus = minus + 1
else
char= ICHAR(c(i))-ICHAR('0')
num(char) = num(char) + 1
end if
end do
num2 = num
do i=1, minus
maxvalue = maxvalue - get_min_num(num)
end do
do i=1, plus
maxvalue = maxvalue + get_min_num(num)
end do
do i=1, N-(minus+plus)*2
maxvalue = maxvalue + get_min_num(num)*10**(i-1)
end do
if(minus.eq.0) then
do i=1, plus
minvalue = minvalue + get_max_num(num2)
end do
do i=1, N-2*plus-num2(0)
minvalue = minvalue + get_max_num(num2)*10**(i-1)
end do
else
minvalue = - maxvalue
endif
print '(i0," ",i0)',maxvalue, minvalue
contains
integer function get_max(num, plus, minus, N) result(maxvalue)
integer::N,i
integer::num(10),plus,minus
integer::digitnum,maxdigit
digitnum = N - plus - minus
maxdigit = digitnum - plus - minus
maxvalue = 0
do i=1,minus
do
end do
end do
end function get_max
function get_min_num(num) result(v)
integer::num(0:9)
integer::i, v
do i=0, 9
if(num(i).ne.0) then
num(i) = num(i)-1
v = i
return
end if
end do
end function get_min_num
function get_max_num(num) result(v)
integer::num(0:9)
integer::i, v
do i=9, 0, -1
if(num(i).ne.0) then
num(i) = num(i)-1
v = i
return
end if
end do
end function get_max_num
end program main
jj