[逻辑推理选择专项练习题]逻辑推理笔试选择专项练习1:数字推理:0 ,6 ,78 ,_____ ,15620A.240B.252C.1020D.77712:你可以随时愚弄某些人。假若以上属实,以下哪些判断必然为真?Ⅰ. 张三和李四随时都可能被你...+阅读
发信人: cynosure (UrsaminoR), 信区: AI
标 题: google挑战赛的练习题
发信站: 天大求实BBS (Mon Dec 12 21:48:54 2005), 本站(bbs.tju.edu)
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[], mands, each element of which contains one of two possible mands. A mand 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 mand 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" mand, it will end up pointing straight to the right. Execute all the mands 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[] mands)
(be sure your method is public)
????
Notes
-
The cursor only paints the canvas if it moves (see example 1
).
Constraints
-
mands will contain between 1 and 50 elements, inclusive.
-
Each element of mands 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 mands in order, the cursor will never lee 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 mands draws a 20 x 20 outline of a square. The cursor is initially at (0, 0) pointing straight down. It then trels to (0, 19) after the first FORWARD mand, painting each pixel along its path with a *. It then rotates 90 degrees left, trels to (19, 19), rotates 90 degrees left, trels to (19, 0), rotates 90 degrees left, and finally trels back to (0, 0).
1)
????
{"LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT", "LEFT"}
延伸阅读:
生理学练习题生理学练习题: 1,下列有关延髓心血管中枢的叙述,哪一项是错误的 A.腹外侧区是心血管交感神经活动的整合部位 B.迷走背核和疑核是心迷走神经中枢 C.安静时心迷走紧张性占优势 D....
C语言练习题2.1以下叙述中正确的是 A)C语言比其他语言高级 B)C语言可以不用编译就能被计算机识别执行 C)C语言以接近英语国家的自然语言和数学语言作为语言的表达形式 D)C语言出现的最晚,具...
google挑战赛练习题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 straigh...
多做练习题结合考试框架,多做练习 练习就是实战练兵,练习就是巩固已了解的知识。来源于考试大。因此一定要多做练习,也就是做到全面复习、重点练习。应试者基本上都是在职人员,平时比较忙,...
环保工程师考试练习题1单选.下列不是由固体废物渗滤液可能产生的危害是( )。 A. 进入土壤使地下水受污染 B .直接流入河流、湖泊和海洋,造成水资源的水质型短缺 C .对当地空气造成污染 D .对土壤...
职称英语补全短文练习题职称英语补全短文练习题Mobile PhonesMobile phones should carry a label if they proved1 to be a dangerous source of radiation, according to Robert Bell, a scienti...
理工类B级练习题职称英语:理工类B级练习题Ford1 Ford's great strength was the manufacturing processnot invention. Long before he started a car pany, he was a worker, known for pic...