博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2018/12/04 PAT刷题 L1-002
阅读量:6923 次
发布时间:2019-06-27

本文共 983 字,大约阅读时间需要 3 分钟。

 

这道题的关键就是在于找到行数和总数之间的规律

import java.util.Scanner;public class Main {    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int n=sc.nextInt();        String c=sc.next();                int i=1;        for(;;i++) {            if (n<2*(i+1)*(i+1)-1) {                break;            }        }        for(int j=i; j>0; j--) {            for(int blank=i-j; blank>0; blank--) {                System.out.print(" ");            }            for(int count=j*2-1; count>0; count--) {                System.out.print(c);            }            System.out.println();        }        for(int j=2; j<=i; j++) {            for(int blank=i-j; blank>0; blank--) {                System.out.print(" ");            }            for(int count=2*j-1; count>0; count--) {                System.out.print(c);            }            System.out.println();        }        System.out.print(n-(2*i*i-1));    }}

 

转载于:https://www.cnblogs.com/huangZ-H/p/10062182.html

你可能感兴趣的文章
怎样快速将PDF转换成Excel文件
查看>>
多功能切菜机的精华所在
查看>>
企业运营系统理念践行者——张恩嘉
查看>>
OC中的数据库
查看>>
我的友情链接
查看>>
Problems about tornado.
查看>>
http协议分析
查看>>
信号量(sem)
查看>>
第五周作业【Linux微职位】
查看>>
MySql入门教程mysql基础知识学习实例讲解
查看>>
const的理解
查看>>
cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
查看>>
设计模式系列 - Composite模式
查看>>
linux配置修改ip地址
查看>>
Shell脚本之Mysql授权
查看>>
开始写博客了
查看>>
SCCM 2007 实现PXE要点
查看>>
[转载]Windows和Linux双系统下完美卸载linux
查看>>
oracle:检查操作系统版本: 必须是 XXX 未通过
查看>>
python中的行结构和缩进
查看>>