Imagination
Imagination
Time Limit : 3000/1000ms (Java/Other)???Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 8???Accepted Submission(s) : 3
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
There are four matrixs blow , Can you image the NEXT matrix from the given information?Input
The first line is a integer which represents the case number .For each test case , there will be a line which contains a integer N (1<=N<=100).
Output
Output the matrix which has N*N integers. Be careful that there is a blank space between twointeger but no blank space after the last integer in a line.
Sample Input
4 1 2 3 4Sample Output
1 1 2 4 3 1 2 3 8 7 4 9 6 5 1 2 3 4 12 11 10 5 13 14 9 6 16 15 8 7AC代碼:
?
#include<iostream>
using namespace std;
int p[100][100];
int main()
{
int n,i,j,k,x,y,t;
cin>>t;
while(t--)
{
?cin>>n;
?k=0;
?x=0;
?if(n==1) cout<<1<<endl;
?else
?{
??while(1)
??{
???if(x==n)? break;
???x++;
???for(i=1;i<=n-x+1;i++)
???{
????p[x][i]=++k;
???}
???for(i=x+1;i<=n;i++)
???{
????p[i][n-x+1]=++k;
???}
???if(x==n)? break;
???x++;
???for(i=n;i>=x;i--)
???{
????p[i][n-x+1]=++k;
???}
???for(i=n-x;i>=1;i--)
???{
????p[x][i]=++k;
???}
??}
??for(i=1;i<=n;i++)
??{
???for(j=1;j<=n;j++)
???{
????if(j==n) cout<<p[i][j]<<endl;
????else cout<<p[i][j]<<" ";
???}
??}
?}
}
?return 0;
}
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/ffhuguang/archive/2012/10/31/2748661.html
總結(jié)
以上是生活随笔為你收集整理的Imagination的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: powerdesigner15(pd)+
- 下一篇: .call() 与 .apply() 的