Problem Statement
You are given a black and white image in a String[], image. Character j of element i (both 0-based indices) of image represents the pixel in row i, column j. 'X' characters represent black pixels and '.' characters represent white pixels. You are given a String[], crops, which contains a series of rectangular crop operations that are performed on the image. Cropping is an operation that trims an image so that only the specified area of the original image remains. Each element of crops is formatted as "r1 c1 r2 c2" (quotes for clarity only), where the upper left corner of the area to crop is at row r1, column c1, and the lower right corner is at row r2, column c2. The coordinates are inclusive. The crop operations are performed in the order that they appear in crops, and each one is performed on the most recent version of the image. The constraints will guarantee that all crop operations will be within the boundaries of the image. Return the final cropped image as a String[] in the same format as the original image String[].
You are given a black and white image in a String[], image. Character j of element i (both 0-based indices) of image represents the pixel in row i, column j. 'X' characters represent black pixels and '.' characters represent white pixels. You are given a String[], crops, which contains a series of rectangular crop operations that are performed on the image. Cropping is an operation that trims an image so that only the specified area of the original image remains. Each element of crops is formatted as "r1 c1 r2 c2" (quotes for clarity only), where the upper left corner of the area to crop is at row r1, column c1, and the lower right corner is at row r2, column c2. The coordinates are inclusive. The crop operations are performed in the order that they appear in crops, and each one is performed on the most recent version of the image. The constraints will guarantee that all crop operations will be within the boundaries of the image. Return the final cropped image as a String[] in the same format as the original image String[].
解决方案 »
- Java初学者到精通需要掌握哪些知识点
- 返回值为什么不能用来区分重载方法
- Jframe被用户最小化后,如何实现在一段时间后还原到原来位置,并显示出来?
- 请问一下图标在哪里
- 如何用Java实现对文件夹操作
- Storefront.java 使用了未经检查或不安全的操作。要了解详细信息,请使用 -Xlint:unchecked 重新编译。
- 想写个会场排序的小程序,遇到个问题,请教一下。我在点击button1后,名字不能在窗口上显示,必须最小化一下,再恢复窗口就看到了,这是怎么回事?求解决办法。
- 关于Sun Java System Application Server的一些问题!分不是问题!
- 高手请进,急~~~~~~~~~~~~~~~~~`
- 一个关于Collections类的问题,求解决!!
- 大家来探讨一下JAVA应用程序怎样做性能测试(主要测试瓶颈)
- 不懂才问----对象和可视化!
Class:
Crop
Method:
crop
Parameters:
String[], String[]
Returns:
String[]
Method signature:
String[] crop(String[] image, String[] crops)
(be sure your method is public)
Constraints
-
image will contain between 1 and 50 elements, inclusive.
-
Each element of image will contain between 1 and 50 characters, inclusive.
-
Each element of image will contain exactly the same number of characters.
-
Each element of image will contain only '.' and uppercase 'X' characters.
-
crops will contain between 1 and 10 elements, inclusive.
-
Each element of crops will be formatted as described in the problem statement and no integers within crops will contain extra leading zeros.
-
Within each element of crops, r2 will be greater than or equal to r1 and c2 will be greater than or equal to c1.
-
crops will contain no operations that exceed the boundaries of the image at any time in the cropping process.
Examples
0)
{".........",
"X.XXXXXXX",
"....X....",
"........." }
{"1 0 2 8", "0 0 1 1"}
Returns: {"X.", ".." }
The first crop effectively removes the top and bottom rows of the image and results in:X.XXXXXXX
....X....The second crop is then performed relative to the new image:X.
..
1)
{"X.X.X.X.X.X.X.X",
".X.X.X.X.X.X.X."}
{"0 0 1 14", "0 0 1 14", "0 0 1 14"}
Returns: {"X.X.X.X.X.X.X.X", ".X.X.X.X.X.X.X." }
These crops don't affect the original image at all.
2)
{".X..X.X.XX.",
"..X..X...X.",
"X......X..X",
".X....X...X",
"..XXXX.X.X.",
"XXX..XXX..X"}
{"0 0 0 0"}
Returns: {"." }3)
{".X..X.X.XX.",
"..X..X...X.",
"X......X..X",
".X....X...X",
"..XXXX.X.X.",
"XXX..XXX..X"}
{"1 0 5 9", "0 1 4 8", "0 0 3 5"}
Returns: {".X..X.", "......", "X....X", ".XXXX." }