1 条题解

  • 0
    @ 2023-6-11 12:17:13

    C :

    #include<stdio.h>
    main()
    {
    	int i,j,n;
    	scanf("%d",&n);
    	for(i=1;i<=n;i++)
    	{
    		for(j=1;j<=n;j++)
    		{
    			if(i==1||i==n)
    			{
    				printf("*");
    			}
    			else
    			{
    			    if(j==1||j==n)
    			    {
    				    printf("*");
    			    }
    			    else
    			        printf(" ");
    		    }
    		}
    		printf("\n");
    	}
    }
    

    C++ :

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

    Java :

    import java.util.*;
        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 j=1;j<=n;j++){
                		if(i==1||i==n||j==1||j==n){
                			System.out.print("*");
                		}
                		else{
                			System.out.print(" ");
                		}
                	}
                	System.out.println();
                }
        }
    }
    

    Python :

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

    信息

    ID
    2412
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者