結果

問題 No.49 算数の宿題
ユーザー jjjj
提出日時 2016-12-27 23:40:45
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 912 bytes
コンパイル時間 1,919 ms
コンパイル使用メモリ 26,624 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 17:35:37
合計ジャッジ時間 2,561 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

program main
  implicit none
  integer::N,len,i,head,tail,res,num,op
  integer,parameter::add=1,mult=2
  character*100::S

  read '(a)',S
  res = 1
  op = mult
  head = 1
  tail = 1
  len = LEN_TRIM(S)

  do
     if(S(tail:tail).eq.'+'.or. &
        S(tail:tail).eq.'*') then
        read(S(head:tail-1),*) num

        if(op.eq.add) then
           res = num + res
        else
           res = num * res
        end if

        if(tail.eq.len+1) then
           exit
        else if(S(tail:tail).eq.'+') then
           op = mult
        else
           op = add
        end if

        head = tail + 1
        tail = tail + 1
     else if (tail.eq.len+1) then
        read(S(head:tail-1),*) num
        if(op.eq.add) then
           res = num + res
        else
           res = num * res
        end if
        exit
     else
        tail = tail + 1
     end if
  end do
  print '(i0)', res
end program main
0