Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
2012/11/16 問題1
Search
mizti
November 18, 2012
550
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
660
Maze Maker
mizti
0
630
「銀将ご乱心」
mizti
0
990
paint.pdf
mizti
1
640
kaibun.pdf
mizti
0
660
dfs1.pdf
mizti
0
610
問題1. 解答例
mizti
0
510
Featured
See All Featured
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
The SEO Collaboration Effect
kristinabergwall1
1
550
Between Models and Reality
mayunak
4
450
Evolving SEO for Evolving Search Engines
ryanjones
0
280
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
990
Ruling the World: When Life Gets Gamed
codingconduct
0
330
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.9k
Deep Space Network (abreviated)
tonyrice
0
300
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
880
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
520
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が必要)