hdu2565java
放大的X
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12576 Accepted Submission(s):
3992
如3*3的’X’应如下所示:
X X
X
X X
5*5的’X’如下所示:
X X
X X
X
X X
X X
接下来有T行,每行有一个正奇数n(3 <= n <= 79),表示放大的规格。
import java.util.Scanner;
public class Main2565 {
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
int [][]a;
int n=cin.nextInt();
while(n-->0){
int m=cin.nextInt();
a=new int[m][m];
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
if(i==j||i+j==m-1){
a[i][j]=1;
}
else if(i+j<m-1&&i!=j){
a[i][j]=2;
}
else if(i>j&&i+j>=m){
a[i][j]=2;
}
}
}
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
if(a[i][j]==1){
System.out.print("X");
}
if(a[i][j]==2){
System.out.print(" ");
}
}
System.out.println();
}
System.out.println();
}
}
}