2018/12/04 PAT刷题 L1-002
这道题的关键就是在于找到行数和总数之间的规律
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)); } }