1 条题解

  • 0
    @ 2025-4-7 21:28:47

    C :

    #include<stdio.h>
    int main(){
      char c[5][5]={{' ',' ','*',' ',' '},
                    {' ','*',' ','*',' '},
                    {'*',' ',' ',' ','*'},
                    {' ','*',' ','*',' '},
                    {' ',' ','*',' ',' '}};
      int i,j;
      for(i=0;i<5;i++){
        for(j=0;j<5;j++)
          printf("%c",c[i][j]);
        printf("\n");
      }
      return 0;
    }
    

    C++ :

    #include <stdio.h>
    int main() {
    	char diamond[5][5] = {
    		{' ', ' ', '*', ' ', ' '},
    		{' ', '*', ' ', '*', ' '},
    		{'*', ' ', ' ', ' ', '*'},
    		{' ', '*', ' ', '*', ' '},
    		{' ', ' ', '*', ' ', ' '}};
    	int i, j;
    	for (i = 0;i < 5;i++) {
    		for (j = 0;j < 5;j++)
    			printf("%c", diamond[i][j]);
    		puts("");
    	}
    	return 0;
    }
    
    

    Pascal :

    
    
    var
      s:string;
    begin
      s:=space(5); s[3]:='*';
      writeln(s);
      s:=space(5); s[2]:='*'; s[4]:='*';
      writeln(s);
      s:=space(5); s[1]:='*'; s[5]:='*';
      writeln(s);
      s:=space(5); s[2]:='*'; s[4]:='*';
      writeln(s);
      s:=space(5); s[3]:='*';
      writeln(s);  
    end.
    
    

    Java :

    
    
    public class Main {
      public static void main(String[] args) {
          String str = ""+
        		       "  *  \n"+
    
                       " * * \n"+ 
    
                       "*   *\n"+
    
                       " * * \n" +
    
                       "  *  \n" ;
          System.out.println(str);
      }
    }
    
    

    Python :

    def f(a):
     b = ' ' * (3 - a) + '*' + ' ' * (a - 1)
     return b+b[0: 2][::-1]
    for i in range(1, 4):
     print f(i)
    for i in range(2, 0, -1):
     print f(i)
    
    • 1

    信息

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