发信人: cynosure (UrsaminoR), 信区: AI
标 题: google挑战赛的练习题
发信站: 天大求实BBS (Mon Dec 12 21:48:54 2005), 本站()
Problem Statement
A simple line drawing program uses a blank 20 x 20 pixel canvas and a directional cursor that starts at the upper left corner pointing straight down. The upper left corner of the canvas is at (0, 0) and the lower right corner is at (19, 19). You are given a String[], commands, each element of which contains one of two possible commands. A command of the form "FORWARD x" means that the cursor should move forward by x pixels. Each pixel on its path, including the start and end points, is painted black. The only other command is "LEFT", which means that the cursor should change its direction by 90 degrees counterclockwise. So, if the cursor is initially pointing straight down and it receives a single "LEFT" command, it will end up pointing straight to the right. Execute all the commands in order and return the resulting 20 x 20 pixel canvas as a String[] where character j of element i represents the pixel at (i, j). Black pixels should be represented as uppercase 'X' characters and blank pixels should be represented as '.' characters.
Definition
Class:
DrawLines
Method:
execute
Parameters:
String[]
Returns:
String[]
Method signature:
String[] execute(String[] commands)
(be sure your method is public)
????
Notes
-
The cursor only paints the canvas if it moves (see example 1).
Constraints
-
commands will contain between 1 and 50 elements, inclusive.
-
Each element of commands will be formatted as either "LEFT" or "FORWARD x" (quotes for clarity only), where x is an integer between 1 and 19, inclusive, with no extra leading zeros.
-
When executing the commands in order, the cursor will never leave the 20 x 20 pixel canvas.
Examples
0)
????
{"FORWARD 19", "LEFT", "FORWARD 19", "LEFT", "FORWARD 19", "LEFT", "FORWARD 19"}
Returns:
{"XXXXXXXXXXXXXXXXXXXX",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"X..................X",
"XXXXXXXXXXXXXXXXXXXX" }
This sequence of commands draws a 20 x 20 outline of a square. The cursor is initially at (0, 0) pointing straight down. It then travels to (0, 19) after the first FORWARD command, painting each pixel along its path with a '*'. It then rotates 90 degrees left, travels to (19, 19), rotates 90 degrees left, travels to (19, 0), rotates 90 degrees left, and finally travels back to (0, 0).
1)
????
{"LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT"}
Returns:
{"....................",
google挑战赛的练习题
才干屋
人气:2.11W
猜你喜欢
- 1Google命马瑟为董事兼审计委员会主席
- 2英文简历(管理员)CONTROLLER(General)
- 3Google员工教你如何通过面试
- 4Google笔经
- 5Google试水点击通话广告业务 扩大收入渠道
- 6Google笔试的败笔
- 7西安交大学子面试google经历
- 8Google笔试记
- 9励志格言:Keep on going Never give up等
- 10雅虎变脸与百度、Google正面交锋
- 11google选择题摘选
- 12英语名言警句nothing is impossible to a willing mind
- 13google笔试题zz
- 14大学生英语演讲稿 Knowledge collaboration and all-round education
- 15Google前招聘官:获得苹果、谷歌或微软工作的10个建议
最近更新
- 1英文求职信-Tourism - Hotel Manager
- 2LOGO设计实习日记
- 3凹凸电子笔试题目(Linux Software Engineer)
- 4甲骨文(Oracle)笔试经验(Oracle Management Trainee与技术笔试题)
- 5CA Technologies2012校招网申指南
- 6LOREAL的Open Question
- 7英语面试: Why are you leaving your present job?
- 8LOGO设计比赛活动策划书
- 9环保协会Logo设计大赛策划书
- 10Technology职位面试3篇
- 11英文求职信-Logistics - Assistant Logistics Supervisor
- 12google挑战赛练习题
- 13高露洁(Colgate)笔试题目
- 14EdgavAnselMowrev的名言
- 15泰鼎(Trident) 笔试题目(IC logic design CM方向)
- 16挑战杯红旅赛道
- 17Technology Analyst职位面试2篇
- 18《民族的机遇与挑战》练习题
推荐内容
- 1国庆节做活动总结6篇
- 2核酸检测员的工作总结参考5篇
- 3小学三好生申请书范文
- 4医学生毕业自我鉴定医学生毕业生鉴定表自我鉴定6篇 拥抱医学职业的恒心与担当:一位医学生毕业的自我鉴定
- 5租房合同协议范本4篇 "租房协议范本:保障公平合法,规避争议风险"
- 6安全教育课观后感8篇
- 72022年关于夏季防溺水安全教育演讲稿范文5篇
- 814岁自我介绍的范本
- 9小学生观看《新时代好少年》观后感
- 10教师节作文集锦7篇 致敬师德,致谢教育—教师节作文佳作!
- 11《史记》小学生读后感4篇 《史记》:小学生探索历史的精彩世界
- 12幼儿教师2023个人总结模板5篇
- 13幼儿教学工作计划集合3篇 创意拓展:启蒙教育蓝图
- 14最新《陪孩子走过小学六年》精选读后感范文三篇
- 152023领班年终总结推荐7篇