結果

問題 No.193 筒の数式
ユーザー jjjj
提出日時 2016-09-16 23:51:33
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,478 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 34,152 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 15:14:37
合計ジャッジ時間 896 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

program main
  implicit none
  character*10::S
  character,allocatable::SS(:)
  integer::len,i,j,head,tail
  integer*8::num(5),opn,maxnum
  data opn/0/,maxnum/-100000000/
  read *,S
  len = LEN_TRIM(S)
  allocate(SS(len))
  call string2array(S,SS)

  do i=1,len
     SS = CSHIFT(SS,1)
     call array2string(S,SS)
     if(is_valid(S).eqv..true.)then
        num = 0
        opn = 0
        head = 1
        do j=2,len-1
           if(S(j:j).eq.'+'.or.S(j:j).eq.'-') then
              tail = j - 1
              opn  = opn + 1
              read(S(head:tail),*) num(opn)
              head = j
           end if
        end do
        tail = len
        opn  = opn + 1
        read(S(head:tail),*) num(opn)
        maxnum = MAX(maxnum, SUM(num(1:opn)))
     end if
  end do
  print '(i0)', maxnum

contains
  logical function is_valid(S) result(l)
    character*10::S
    integer::m
    m = LEN_TRIM(S)
    if(S(1:1).ne.'+'.and.S(1:1).ne.'-' .and. &
       S(m:m).ne.'+'.and.S(m:m).ne.'-') then
       l = .true.
    else
       l = .false.
    end if
  end function is_valid
  subroutine string2array(S,SS)
    implicit none
    character::SS(:)
    character*10::S
    integer::i
    do i=1,LEN_TRIM(S)
       SS(i) = S(i:i)
    end do
  end subroutine string2array
  subroutine array2string(S,SS)
    implicit none
    character::SS(:)
    character*10::S
    integer::i
    do i=1,LEN_TRIM(S)
       S(i:i) = SS(i)
    end do
  end subroutine array2string
end program main

0