HDOJ/HDU 2565 放大的X(分段思考~)

Problem Description

请你编程画一个放大的’X’。

如3*3的’X’应如下所示:

X X XX X5*5的’X’如下所示:X X X X X X XX X

Input

输入数据第一行是一个整数T,表示有T组测试数据;

接下来有T行,每行有一个正奇数n(3 <= n <= 79),表示放大的规格。

Output

对于每一个n打印一个规格为n * n放大的’X’;每组输出后面空一行。

Sample Input

2

3

5

Sample Output

X X
 X
X X

X   X
 X X
  X
 X X
X   X

我是将输出分成3部分来思考的。这样容易解决问题一些。

你们看我代码很容易理解的。

import java.util.Scanner;

/**
 * @author 陈浩翔
 * 2016-6-5
 */
public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            int n=sc.nextInt();
            int m=n/2+1;//中间值
            for(int i=1;i<m;i++){
                for(int a=1;a<i;a++){
                    System.out.print(" ");
                }
                System.out.print("X");
                for(int a=1;a<=n-i*2;a++){
                    System.out.print(" ");
                }
                System.out.print("X");
                System.out.println();
            }
            for(int i=1;i<m;i++){
                System.out.print(" ");
            }
            System.out.print("X");
            System.out.println();

            for(int i=m-1;i>=1;i--){
                for(int a=1;a<i;a++){
                    System.out.print(" ");
                }
                System.out.print("X");
                for(int a=1;a<=n-i*2;a++){
                    System.out.print(" ");
                }
                System.out.print("X");
                System.out.println();
            }
            System.out.println();
        }
    }
}
时间: 2024-08-11 10:46:07

HDOJ/HDU 2565 放大的X(分段思考~)的相关文章

HDU 2565 放大的X

放大的X Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8695    Accepted Submission(s): 2618 Problem Description 请你编程画一个放大的'X'. 如3*3的'X'应如下所示: X X X X X 5*5的'X'如下所示: X X X X X X X X X Input 输入数据第一

HDOJ/HDU 2140 Michael Scofield&#39;s letter(字符转换~)

Problem Description I believe many people are the fans of prison break. How clever Michael is!! In order that the message won't be found by FBI easily, he usually send code letters to Sara by a paper crane. Hence, the paper crane is Michael in the he

HDU 3911 Black And White 分段树 题解

Problem Description There are a bunch of stones on the beach; Stone color is white or black. Little Sheep has a magic brush, she can change the color of a continuous stone, black to white, white to black. Little Sheep like black very much, so she wan

HDOJ/HDU 1161 Eddy&#39;s mistakes(大写字母转换成小写字母)

Problem Description Eddy usually writes articles ,but he likes mixing the English letter uses, for example "computer science" is written frequently "coMpUtEr scIeNce" by him, this mistakes lets Eddy's English teacher be extremely disco

HDOJ/HDU 1250 Hat&#39;s Fibonacci(大数~斐波拉契)

Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1. F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4) Your task is to take

HDU 1754 I hate it 分段树Segment Tree题解

给出一段数据,然后要更新单个数据,会询问一段数据中的最大值. 又是一道分段树操作.渐渐熟手了. #pragma once #include <cstdio> #include <algorithm> using namespace std; class IHateIt_1754_1 { static const int SIZE = 200001; int *segTree; //不要使用segTree[SIZE<<2] inline int lChild(int r)

HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)

Problem Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now. The game can be played by two or more t

HDOJ(HDU) 2500 做一个正气的杭电人(水~)

Problem Description 做人要有一身正气,杭电学子都应该如此.比如我们今天的考试就应该做到"诚信"为上. 每次考试的第一个题目总是很简单,今天也不例外,本题是要求输出指定大小的"HDU"字符串,特别地,为了体现"正气"二字,我们要求输出的字符串也是正方形的(行数和列数相等). Input 输入的第一行包含一个正整数N(N<=20),表示一共有N组数据,接着是N行数据,每行包含一个正整数M(M<=50),表示一行内有M个

HDOJ/HDU 2203 亲和串(简单的判断~Java的indexOf()方法秒)

Problem Description 人随着岁数的增长是越大越聪明还是越大越笨,这是一个值得全世界科学家思考的问题,同样的问题Eddy也一直在思考,因为他在很小的时候就知道亲和串如何判断了,但是发现,现在长大了却不知道怎么去判断亲和串了,于是他只好又再一次来请教聪明且乐于助人的你来解决这个问题. 亲和串的定义是这样的:给定两个字符串s1和s2,如果能通过s1循环移位,使s2包含在s1中,那么我们就说s2 是s1的亲和串. Input 本题有多组测试数据,每组数据的第一行包含输入字符串s1,第二