1 条题解

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

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	int i,n,j;
    	cin>>n;
    	for(i=1;i<=n;i++){
    		cout<<setw(n-i)<<"";
    		for(j=1;j<=i*2-1;j++){
    			cout<<j;
    		}
    		cout<<endl;
    	}
    	return 0;
    } 
    

    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 <= n - i; k++) {
    			System.out.print(" ");
    			
    		}
    		
    		for(int j = 1; j <= 2 * i - 1 ; j++) {
    			System.out.print(j);
    		}
    		System.out.print('\n');
    	}
    
    }
    }
    

    Python :

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

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

    信息

    ID
    2640
    时间
    1000ms
    内存
    64MiB
    难度
    3
    标签
    递交数
    87
    已通过
    46
    上传者