0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

素人が考えた逆ポーランド記法への変換手順

Last updated at Posted at 2025-07-11

基本情報取らないといけないのに、動画何本見ても逆ポーランド記法が分からない人が苦し紛れに考えた手順です・・・

一応、下記サイトで答え合わせは出来ました。
https://hamanegi.com/memo/article/polish_notation_converter

  1. 優先するべき計算を括弧でくくる。
    ※この時、乗算・除算もくくる。
  2. 括弧でくくった単位で逆ポーランド記法に変換する。
    ※括弧が多段階になる場合は、深い階層の括弧から変換していく。
  3. 最後に、括弧でくくられた被演算子同士を逆ポーランド記法に変換する。

書いててよく分からなくなったので実際にやってみる。

逆ポーランド記法に変換したい普通の式(適当)
↓
(2+4)*(9+4)+(9/8+3)/3+(4-1)/7+12*2-3+7+(3*12+4)+1

*/ の計算を括弧でくくる。
これで、括弧の外に */ は存在しなくなる。
((2+4)*(9+4))+(((9/8)+3)/3)+((4-1)/7)+(12*2)-3+7+((3*12)+4)+1

次に、深い階層の括弧内の式(演算子)から、逆ポーランド記法にする。
3重括弧が最深なので、まずは3重括弧内の式(9/8)が対象。
((2+4)*(9+4))+(((98/)+3)/3)+((4-1)/7)+(12*2)-3+7+((3*12)+4)+1

次に、2重括弧内の式(演算子)を逆ポーランド記法にする。
((24+)*(94+))+(((98/)3+)/3)+((41-)/7)+(12*2)-3+7+((312*)+4)+1

次に、1重括弧内の式(演算子)を逆ポーランド記法にする。
((24+)(94+)*)+(((98/)3+)3/)+((41-)7/)+(122*)-3+7+((312*)4+)+1

次に、括弧外の式(演算子)を逆ポーランド記法にする。
((24+)(94+)*)(((98/)3+)3/)((41-)7/)(122*)37((312*)4+)1+++-+++

括弧を全部消す。
24+94+*98/3+3/41-7/122*37312*4+1+++-+++
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?