Blue Bridge cup of java-based practice letters graphics

Basic exercises letter graphics

Resource constraints

Time limit: 1.0s Memory Limit: 256.0MB

Problem Description

Use of the letters can form some beautiful graphics, an example is given below:

ABCDEFG

BABCDEF

CBABCDE

DCBABCD

EDCBABC

This is a pattern row 5 7, find the pattern of this rule, and outputs a pattern of n rows and m columns.

Input Format

Input line, comprising two integers n and m, respectively represent the number of columns you want output pattern lines.

Output Format

N output lines, each m characters for your graphics.

Sample input

5 7

Sample Output

ABCDEFG
BABCDEF
CBABCDE
DCBABCD
EDCBABC

Data size and convention

1 <= n, m <= 26。

import java.util.Scanner;  
    public class Main {  
      
        public static void main(String[] args) {  
            Scanner input=new Scanner(System.in);  
            int n=input.nextInt();  
            int m=input.nextInt();  
            char[][] charArr=new char[n][m];  
            input.close();  
            char[] c=new char[m>n?m:n];  
            int tc=65;  
            for (int i = 0; i < c.length; i++) {  
                c[i]=(char)tc;  
                tc++;  
            }  
            for (int i = 0; i < n; i++) {  
                for (int j = 0; j < n-i&&i<m; j++) {  
                    charArr[j+i][i]=c[j];  
                }  
                for (int j = 0; j < m-i; j++) {  
                    charArr[i][j+i]=c[j];  
                }  
            }  
            for (int i = 0; i < n; i++) {  
                for (int j = 0; j < m; j++) {  
                    System.out.print(charArr[i][j]);  
                }  
                System.out.println();  
            }  
        }  
      
    }
Published 24 original articles · won praise 2 · Views 184

Guess you like

Origin blog.csdn.net/weixin_44570019/article/details/104515649