Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
2012/11/16 問題1
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
mizti
November 18, 2012
540
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
2012/11/16 問題1
mizti
November 18, 2012
More Decks by mizti
See All by mizti
CutSticks.pdf
mizti
0
650
Maze Maker
mizti
0
620
「銀将ご乱心」
mizti
0
980
paint.pdf
mizti
1
640
kaibun.pdf
mizti
0
650
dfs1.pdf
mizti
0
610
問題1. 解答例
mizti
0
510
Featured
See All Featured
New Earth Scene 8
popppiees
3
2.4k
So, you think you're a good person
axbom
PRO
2
2.1k
Building the Perfect Custom Keyboard
takai
2
820
We Are The Robots
honzajavorek
0
280
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
420
The Limits of Empathy - UXLibs8
cassininazir
1
550
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
72
40k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
230
A Tale of Four Properties
chriscoyier
163
24k
Transcript
問題1.ポーの惑星 イントロダクション イントロダクション イントロダクション イントロダクション: あなたがある朝目覚めるとあなたは見知らぬ惑星にいました。この惑星では四 則演算の書き方が地球とは異なるようです。 地球で 3 +
6 と書くはずのところでは (+ 3 6)と演算子を最初に書いて、それを( ) で括るようです。 また、9 – ( 2 + 1) は (- 9 (+ 2 1 ) ) となるようです。 この惑星の科学者やビジネスマンは長い長い式の計算に日々追い立てられ、苦 しんでいるようでした。 あなたはPCを持ったままこの惑星に来たようです。せっかくなのでこの惑星の人 たちのために、式の自動的に計算を行なってあげるプログラムを作ってあげま しょう。
問題1.ポーの惑星 • Input: 入力は以下のような形式の一行のテキストからなる式です。 • 数字 • + - *
の3種類の演算子 • ( ) および半角スペース から構成され、以下のように記述されています。 ( + 4 9 ) あるいは ( - 9 (+ 11 300)) すなわち、式は(演算子 式または数字 式または数字) という方法で記載されてい ます。 数字は-1000から1000の間であり、数字と数字の間、数字と演算子は1文字以 上の半角スペースで分かたれています。カッコと数字の間、カッコとカッコの間は スペースで区切られているとは限りません。 • Output: 各入力に対し,計算の結果を1行に出力してください。 それ以外の余計な文字を 含んではいけません。答えが負数であることはあり得ます。
問題1.ポーの惑星 Sample Input: (+ 6 8) Sample Output: 14 Sample
Input: (+ 5 (- 8 3)) Sample Output: 10 Sample Input: (+ (* (- 9 4) 8) (- 8 3)) Sample Output: 45 Sample Input: (* (- 9 20) (+ 7 (- 999 108)) ) Sample Output: -9878 できたら、
[email protected]
まで送付お願いします。 実行イメージ # cat input.txt (- 8 3) # cat input.txt | ruby a.rb 5 標準入力はRubyなら STDIN.gets.chomp などで拾えます。 (STDIN.getsは改行コードが 入ってしまうためchompが必要)