Questions for Google program Competitions

Source: Internet
Author: User
ArticleDirectory
    • Problem Statement
    • Definition
    • Notes
    • Constraints
    • Examples
    • Problem Statement
    • Definition
    • Constraints
    • Examples
    • Problem Statement
    • Definition
    • Constraints
    • Examples
Are simple:

Problem Statement
A simple line drawing program uses a blank 20x20 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 shocould 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 shoshould change its direction by 90 degrees counterclockwise. so, if the cursor is initially pointing straight down and it takes es a single "Left" command, it will end up pointing straight to the right. execute all the commands in order and return the resulting 20x20 pixel canvas as a string [] Where character J of element I represents the pixel at (I, j ). black pixels shoshould be represented as uppercase 'X' characters and blank pixels shoshould be represented '. '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
- CommandsWill contain between 1 and 50 elements, inclusive.
- Each elementCommandsWill be formatted as either "Left" or "forward X" (quotes for clarity only), where X is an integer between 1 and 19, intrusive, with no extra leading zeros.
- When executingCommandsIn order, the cursor will never leave the 20x20 pixel canvas.
Examples
0)
{"Forward 19", "Left", "Forward 19", "Left", "Forward 19", "Left", "Forward 19 "}
 Returns: {"xxxxxxxxxxxxxxxxxx", "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 20x20 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 '*'. 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" }
 Returns :{".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... "} 
the cursor spins round and round, but never actually paints any pixels. The result is an empty canvas.
2)
 {"Forward 1"} 
 Returns: {"x ................... "," X ................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... ",".................... "} 
going forward by one pixel creates a line that is 2 pixels long because both the start and end points are painted.
3)
{"Left", "Forward 19", "Left", "forward 18", "Left ", "forward 17", "Left", "Forward 16", "Left", "forward 15 ", "Left", "forward 14", "Left", "forward 13", "Left ", "Left", "Left", "forward 12", "Left", "Forward 11", "Left", "Left ", "Left", "Forward 10", "Left", "Forward 9", "Left ", "Forward 8", "Left", "forward 7 "}
Returns: {"xxxxxxxxxxxxxxxxxx ","................... X ",".. xxxxxxxxxxxxxxxx. X ",".. X .............. x. X ",".. x. xxxxxxxxxxxx. x. X ",".. x. X .......... x. x. X ",".. x. x. XXXXXXXX. 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 ........ x. x. X ",".. x. x. X ........ x. x. X ",".. x. x. xxxxxxxxxx. x. X ",".. x. X ............ x. X ",".. x. xxxxxxxxxxxxxx. X ",".. X ................ X ",".. xxxxxxxxxxxxxxxxxx ",".................... "}

This problem statement is the exclusive and proprietary property of topcoder, Inc. any unauthorized use or reproduction of this information without the prior written consent of topcoder, Inc. is strictly prohibited. (c) 2003, topcoder, Inc. all rights reserved.

Problem Statement
a square matrix is a grid of nxn numbers. for example, the following is a 3x3 matrix:
 4 3 5 2 4 5 0 1 9 

one way to represent a matrix of numbers, each of which is between 0 and 9 random Sive, is as a row-major string. to generate the string, simply concatenate all of the elements from the first row followed by the second row and so on, without any spaces. for example, the above matrix wocould be represented as "435245019 ".

you will be given a square matrix as a row-major string. your task is to convert it into a string [], where each element represents one row of the original matrix. element I of the string [] represents row I of the matrix. you shoshould not include any spaces in your return. hence, for the above string, you wocould return {"435", "245", "019 "}. if the input does not represent a square matrix because the number of characters is not a perfect square, return an empty string [], {}.

Definition
Class: Matrixtool
Method: Convert
Parameters: String
Returns: String []
Method signature: String [] convert (string S)
(Be sure your method is public)
Constraints
- SWill contain between 1 and 50 digits, random Sive.
Examples
0)
"435245019"
Returns: {"435", "245", "019 "}
The example above.
1)
"9"
Returns: {"9 "}
2)
"0123456789"
Returns :{}
This input has 10 digits, and 10 is not a perfect square.
3)
"3357002966366183191503444273807479559869883303524"
Returns: {"3357002", "9663661", "8319150", "3444273", "8074795", "5986988 "}

This problem statement is the exclusive and proprietary property of topcoder, Inc. any unauthorized use or reproduction of this information without the prior written consent of topcoder, Inc. is strictly prohibited. (c) 2003, topcoder, Inc. all rights reserved.

Problem Statement
When editing a single line of text, there are four keys that can be used to move the cursor: end, home, left-arrow and right-arrow. as you wowould perform CT, left-arrow and right-arrow move the cursor one character left or one character right, unless the cursor is at the beginning of the line or the end of the line, respectively, in which case the keystrokes do nothing (the cursor does not wrap to the previous or next line ). the Home key moves the cursor to the beginning of the line, and the end key moves the cursor to the end of the line.

You will be given a int,N, Representing the number of character in a line of text. the cursor is always between two adjacent characters, at the beginning of the line, or at the end of the line. it starts before the first character, at position 0. the position after the last character on the line is positionN. You shoshould simulate a series of keystrokes and return the final position of the cursor. you will be given a string where characters of the string represent the keystrokes made, in order. 'l' and 'R' represent left and right, while 'H' and 'E' represent home and end.

Definition
Class: Cursorposition
Method: Getposition
Parameters: String, int
Returns: Int
Method signature: Int getposition (string keystrokes, int N)
(Be sure your method is public)
Constraints
- KeystrokesWill be contain between 1 and 50 'l', 'R', 'h', and 'E' characters, inclusive.
- NWill be between 1 and 100, inclusive.
Examples
0)
"Erlll"
10
Returns: 7
First, we go to the end of the line at position 10. then, the right-arrow does nothing because we are already at the end of the line. finally, three left-arrows brings us to position 7.
1)
"Ehheehllllrrrrrr"
2
Returns: 2
All the right-arrows at the end ensure that we end up at the end of the line.
2)
"Elllellrrrrlrlrlllrlllrllllllrllrrrl"
10
Returns: 3
3)
"Rrleerllllrllrlrrrlrlrlrlrlllll"
19
Returns: 12

This problem statement is the exclusive and proprietary property of topcoder, Inc. any unauthorized use or reproduction of this information without the prior written consent of topcoder, Inc. is strictly prohibited. (c) 2003, topcoder, Inc. all rights reserved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.