标签:
小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示:
对方同时也需要在电脑dos窗口中以字符的形式输出该标志,并能任意控制层数。
1 import java.util.Scanner; 2 3 public class Main { 4 public static void main(String[] args) { 5 int n = new Scanner(System.in).nextInt(); 6 char a[][] = new char[n * 4 + 5][n * 4 + 5]; 7 for (int i = 0; i < a.length; i++) { 8 for (int j = 0; j < a[i].length; j++) { 9 a[i][j] = ‘.‘; 10 } 11 } 12 int t = 0; 13 for (int i = 0; i < n; i++, t += 2) { 14 for (int j = t + 2; j < a.length - t - 2; j++) { 15 a[t][j] = ‘$‘; 16 a[j][t] = ‘$‘; 17 a[a.length - t - 1][j] = ‘$‘; 18 a[j][a.length - t - 1] = ‘$‘; 19 } 20 for (int j = t; j <= t + 2; j++) { 21 a[j][t + 2] = ‘$‘; 22 a[t + 2][j] = ‘$‘; 23 a[a.length - t - 3][j] = ‘$‘; 24 a[j][a.length - t - 3] = ‘$‘; 25 } 26 for (int j = a.length - 1 - t - 2; j <= a.length - 1 - t; j++) { 27 a[j][t + 2] = ‘$‘; 28 a[t + 2][j] = ‘$‘; 29 a[a.length - 1 - t - 2][j] = ‘$‘; 30 a[j][a.length - 1 - t - 2] = ‘$‘; 31 } 32 } 33 int m = a.length / 2; 34 for (int j = a.length / 2 - 2; j <= m + 2; j++) { 35 a[j][m] = a[m][j] = ‘$‘; 36 } 37 38 for (int i = 0; i < a.length; i++) { 39 for (int j = 0; j < a[i].length; j++) { 40 System.out.print(a[i][j]); 41 } 42 System.out.println(); 43 } 44 } 45 }
评测点序号 | 评测结果 | 得分 | CPU使用 | 内存使用 | 下载评测数据 |
---|---|---|---|---|---|
1 | 正确 | 50.00 | 218ms | 24.33MB | 输入 输出 |
2 | 正确 | 50.00 | 234ms | 25.00MB | 输入 输出 |
标签:
原文地址:http://www.cnblogs.com/wuqianling/p/5343221.html