马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
输入n 和 m 输出n*m的回型矩阵 从左上角1开始 但是自己调试输出时间很长 提交oj也超时! 希望知道哪里出现问题!谢谢#include<stdio.h>
int sz[10][10];
int main(void)
{
int a = 0, b = 0;
int c = 0, num = 0;
int n=0,i=1,j=1;
int pd;
int d = 0, e = 0;
while (scanf("%d %d", &a, &b) != EOF)
{
d = a, e = b;
c = 1;
num = 0;
n = a * b;
i = 1,j = 1;
pd = 0;
while (num<n)
{
while (j<b)
{
sz[i][j++] = ++num;
if (num == n)
{
i = 100;
j = 100;
c = 100;
}
}
while (i < a)
{
sz[i++][j] = ++num;
if (num == n)
{
i = 100;
j = 100;
c = 100;
}
}
while (j>c)
{
sz[i][j--] = ++num;
if (num == n)
{
i = 100;
j = 100;
c = 100;
}
}
while (i >(c+1))
{
sz[i--][j] = ++num;
if (num == n)
{
i = 100;
j = 100;
c = 100;
}
}
a -= 1, b -= 1, c++;
}
for (i = 1; i <= d; i++)
{
for (j = 1; j <= e; j++)
{
printf("%2d ", sz[i][j]);
}
printf("\n");
}
}
return 0;
}
|