"Waterloo Cup" "Basic exercise 11" "Alphabet Graphics"

Source: Internet
Author: User
Tags stringbuffer

Title: Alphabet graphic

Problem description
Using letters to make up some beautiful graphics, here's an example:
ABCDEFG
Babcdef
Cbabcde
Dcbabcd
Edcbabc
This is a 5 row 7 column of graphics, please find out the pattern of this graph, and output a n row m column of graphics.
Input format
Enter a line that contains two integers n and m, representing the number of rows in the graph you want to output.
Output format
Output n rows, each M-character, for your graphics.
Sample input
5 7
Sample output
ABCDEFG
Babcdef
Cbabcde
Dcbabcd
Edcbabc
Data size and convention
1 <= N, M <= 26.


Analysis: Up to 26 English letters, each letter set is a subset of these 26 letters, so create an internal class to be responsible for generating the letter set, and then only need to remove the last character each time, the first one to add a character to form the next line of character sequence.


Source:

public class Test007 {public static void main (string[) args) {Scanner sc = new Scanner (system.in);
		int row = Sc.nextint ();
		int col = Sc.nextint ();
		
		Sc.close ();
		ABC abc = new ABC (COL);
		StringBuffer sb = new StringBuffer (Abc.getcontent ());
		System.out.println (Abc.getcontent ());
			for (int i=1; i<row; i++) {//delete last character Sb.deletecharat (Sb.length ()-1);
			char ch = sb.charat (0);
			Inserts a character sb.insert (0, Abc.getprefix (CH)) at the front;
		System.out.println (SB); }//Create an inner class that is responsible for generating the content string and getting the first character of a character is how much private static class abc{private static final String original = "ABCDE
		FGHIJKLMNOPQRSTUVWXYZ ";
		
		Private String content;
		Public ABC (int len) {this.content = original.substring (0, Len);
		Public String getcontent () {return content;
			Public char getprefix (char ch) {int index = CONTENT.INDEXOF (CH);
			index++;
			if (index = = Content.length ()) {index = 0;
		Return Content.charat (index); }
	}
}


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.