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
560
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
2012/11/16 問題1
mizti
November 18, 2012
Transcript
3 slides
問題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が必要)
More Decks by mizti
See All by mizti
CutSticks.pdf
mizti
0
660
Maze Maker
mizti
0
640
「銀将ご乱心」
mizti
0
990
paint.pdf
mizti
1
650
kaibun.pdf
mizti
0
660
dfs1.pdf
mizti
0
620
問題1. 解答例
mizti
0
520
Featured
See All Featured
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
690
The Curse of the Amulet
leimatthew05
4
17k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
570
Amusing Abliteration
ianozsvald
1
400
New Earth Scene 8
popppiees
5
2.9k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
530
Done Done
chrislema
187
17k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
650
Automating Front-end Workflow
addyosmani
1370
210k
Large-scale JavaScript Application Architecture
addyosmani
516
110k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
1
320
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
580