Problem Statement | |||||||||||||
Sometimes when computer programs have a limited number of colors to use, they use a technique called dithering. Dithering is when you use a pattern made up of different colors such that when the colors are viewed together, they appear like another color. For example, you can use a checkerboard pattern of black and white pixels to achieve the illusion of gray. You are writing a program to determine how much of the screen is covered by a certain dithered color. Given a computer screen where each pixel has a certain color, and a list of all the solid colors that make up the dithered color, return the number of pixels on the screen that are used to make up the dithered color. Each pixel will be represented by a character inscreen. Each character inscreen and in dithered will be an uppercase letter ('A'-'Z') representing a color. Assume that any pixel which is a color contained in dithered is part of the dithered color. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | dithered will contain between 2 and 26 upper case letters ('A'-'Z'), inclusive. | ||||||||||||
- | There will be no repeated characters in dithered. | ||||||||||||
- | screen will have between 1 and 50 elements, inclusive. | ||||||||||||
- | Each element of screen will contain between 1 and 50 upper case letters ('A'-'Z'), inclusive. | ||||||||||||
- | All elements of screen will contain the same number of characters. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
| |||||||||||||
4) | |||||||||||||
|
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.
这首题很简单
public class ImageDithering {
public static int count(String dithered, String[] screen) {
int num = 0;
int ditheredArrayLenth = dithered.length();
int scrLen = 0;
String scr = null;
int c[] = new int[26];
char ch;
char ditheredArray[] = dithered.toCharArray();
int len = screen.length;
for (int i = 0; i < len; i++) {
scr = screen[i];
scrLen = scr.length();
for (int j = 0; j < scrLen; j++) {
ch = scr.charAt(j);
c[ch - 65]++;
}
}
for (int i = 0; i < ditheredArrayLenth; i++)
num += c[ditheredArray[i] - 65];
return num;
}
}