Coder Social home page Coder Social logo

bridge's Introduction

学习笔记

时间: 2018/3/27

题目


/**
 * 根据输入的正整数n (米字形由一个(2n-1)*(2n-1)的矩阵组成,矩阵包含从大写A开始的n个字母
 *   例如:n=3时,包含A,B,C;n=4时,包含A,B,C,D。
 *   矩阵的正中间为n个字母中字典序最大的那个,从这个字母开始,沿着西北、正北、东北、正西、
 * 正东、西南、正南、东南八个方向各有一条由大写字母组成的直线。并且直线上的字母按字典序依次减小,直到大写字母A。
 *   矩阵的其它位置用英文句号.填充。
 * <p>
 *   样例输入一
 *   3
 * <p>
 *   样例输出一
 *   A.A.A
 *   .BBB.
 *   ABCBA
 *   .BBB.
 *   A.A.A
 * <p>
 *   样例输入二
 *   4
 * <p>
 *   样例输出二
 *   A..A..A
 *   .B.B.B.
 *   ..CCC..
 *   ABCDCBA
 *   ..CCC..
 *   .B.B.B.
 *   A..A..A
 *
 * @author times
 * Time: 2017-11-30 00:23
 */
import java.util.Scanner;

public class Test4 {
    static char a = 'A';

    public Test4() {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        solve(n);
    }

    static void solve(int n) {
        int l = 2 * n - 1;
        char[][] x = new char[l][l];
        char[] c = new char[n];
        for (int i = 0; i < n; i++) {
            c[i] = a++;
        }
        for (int i = 0; i < l; i++) {
            for (int j = 0; j < l; j++) {
                x[i][j] = '.';
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    x[i + j * (n - 1 - i)][i + k * (n - 1 - i)] = c[i];
                }
            }
        }
        for (int i = 0; i < l; i++) {
            for (int j = 0; j < l; j++) {
                System.out.print(x[i][j]);
            }
            System.out.println();
        }
    }
}

bridge's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.