JAVA classification game

Classification game

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

Classification games are very suitable for children's education, allowing them to understand more things and learn more knowledge through games. The classification game we want to implement is very simple, a word-based classification game. We give two or three categories, say the first letter of a word, there are two types of letters starting with B and letters starting with C, and there may be three categories. Then give several pictures to represent the things in these two categories, so that the child can drag the following items into the basket corresponding to the initials, plus points for the right, minus points for the wrong.
As a programmer, how can you bear it, so you decided to write a plug-in, instantly kill it, and get full marks. Assuming you've got the data, and while this is sometimes the hardest part, today we're only going to consider what the hack is trying to achieve. The data contains the initials of different categories, and the English words of some items (hehe, this is much better than the picture).
The task of the plug-in is to classify the English words of the items according to the first letter of the category, and output the results respectively.

Input

There are multiple sets of input data.
The first line of each set of data is two positive integers C (2<=C<=5), and N (1<=N<=100) represents the number of categories and the number of words (item names), respectively. The next line has C capital letters, representing the first letter of the category. Next N lines, each line has an English word, representing the specific item name, and the word length does not exceed 20.
Note that it is possible to give words that do not belong to any of the C categories.

Output

For each set of inputs there is a set of outputs. Each set of outputs has C lines in the order given by item category. Each line gives the corresponding word. If there is no such category, it will not be output. If there are more than one, separate them with spaces. A blank line is output after each set of output.

Sample Input

2 5
B C
Bag
Cat
boy
Boss
case
3 3
B C D
Bomb
dog
Donkey

Sample Output

Bag boy Boss
Cat case

Bomb
dog Donkey

import java.util. *;
class People{
	String ch, ch1[];

	public People(String ch, String[] ch1) {
		
		this.ch = ch;
		this.ch1 = ch1;
	}
	public void out(int n, int m)
	{
		String b[] = ch.split(" ");
		for(int i = 0; i < n; i++) {
			int c = 0;//Mark whether the current letter has a string matching it
			for(int j = 0; j < m; j++)//You cannot write j<ch1.length, because ch1 is a defined string array, the length of the array is specified by us, it is always 100, it will not be the current the number of strings stored
			{
				if(ch1[j].startsWith(b[i]) || ch1[j].startsWith(b[i].toLowerCase())) {//See if the first character starts with the letter or in lowercase of the letter form begins
					c++;
					if(c == 1) {
					System.out.print(ch1[j]);
					}
					else {
						System.out.print(" "+ch1[j]);
					}
				}
			}
			if(c == 0) {
				continue;
			}
			else {
			System.out.println();
			}
		}
	}
}
public class Main {
	public static void main(String args[]) {
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()) {
			int c = cin.nextInt ();
			int n = cin.nextInt ();
			String a = cin.nextLine();
			String ch = cin.nextLine();
			String ch1[] = new String[100];
			for(int i = 0; i < n; i++)
			{
				ch1 [i] = cin.nextLine ();
			}
			People people = new People(ch, ch1);//Pass in strings and arrays of strings
			people.out(c, n);
			System.out.println();
		}
   }
}




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324573592&siteId=291194637