1 条题解

  • 0
    @ 2023-6-11 12:20:57

    Java :

    import java.util.Scanner;
    public class Main{
    public static void main (String[] args){
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	for(int i = 1; i <= n; i++) {
    		for(int k = 1; k <= i-1 ; k++) {
    			System.out.print(" ");
    			
    		}
    		
    		for(int j = 1; j <= 2 * n -(2 * i - 1) ; j++) {
    			System.out.print(n + 1 - i);
    		}
    		System.out.print('\n');
    	}
    
    }
    }
    

    Python :

    n = int(input())
    for i in range(1, n + 1):
        for j in range(1, i - 1 + 1):
            print(' ', end='')
        for j in range(1, 2 * (n - i) + 1 + 1):
            print(n - i + 1, end='')
        print()
    
    
    • 1

    【入门】字符图形-数字正三角(3)

    信息

    ID
    2641
    时间
    1000ms
    内存
    64MiB
    难度
    4
    标签
    递交数
    88
    已通过
    44
    上传者