| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 730 人关注过本帖
标题:谁可以帮我改一下代码 代码如下
只看楼主 加入收藏
灬xiaoning
Rank: 2
等 级:论坛游民
帖 子:27
专家分:10
注 册:2010-7-24
结帖率:75%
收藏
已结贴  问题点数:10 回复次数:4 
谁可以帮我改一下代码 代码如下
#include<stdio.h>
int pass;
typedef struct Corner
{
    int a;
    int b;
    int c;
    int d;
};
typedef struct Array
{
    int a[100][100];
    int b[100][100];
    int c[100][100];
    int d[100][100];
};
int GetCorner(int m[100][100],int n)
{
    int flag=0,mid=n/2+1;
    if(n%2!=0){
        if(mid%2!=0 || pass==0){
            if(flag++==0){
                Corner corner;
                corner.a =m[0][0];
                corner.b =m[0][n-1];
                corner.c =m[n-1][0];
                corner.d =m[n-1][n-1];
                printf("%d %d %d %d\n",corner.a,corner.b,corner.c,corner.d);
            }
            if(flag++==1){
                Corner corner;
                corner.a =m[0][0];
                corner.b =m[0][mid-1];
                corner.c =m[mid-1][0];
                corner.d =m[mid-1][mid-1];
                printf("%d %d %d %d\n",corner.a,corner.b,corner.c,corner.d);

            }
            if(flag++==2){
                Corner corner;
                corner.a =m[0][mid-1];
                corner.b =m[0][mid*2-2];
                corner.c =m[mid-1][mid-1];
                corner.d =m[mid-1][mid*2-2];
                printf("%d %d %d %d\n",corner.a,corner.b,corner.c,corner.d);
            }
            if(flag++==3){
                Corner corner;
                corner.a =m[mid-1][0];
                corner.b =m[mid-1][mid-1];
                corner.c =m[mid-1][0];
                corner.d =m[mid*2-2][mid-1];
                printf("%d %d %d %d\n",corner.a,corner.b,corner.c,corner.d);
            }
            if(flag++==4){
                Corner corner;
                corner.a =m[mid-1][mid-1];
                corner.b =m[mid-1][mid*2-2];
                corner.c =m[mid*2-2][mid-1];
                corner.d =m[mid*2-2][mid*2-2];
                printf("%d %d %d %d\n",corner.a,corner.b,corner.c,corner.d);
            }
        }
    }
    return 0;
}
int Div_and_Put_Array(int A[100][100],int n)
{
    Array sz;
    int i,j;
    while(n/2>1){
        for(i=0;i<=n/2;i++)
            for(j=0;j<=n/2;j++)
                sz.a [i][j]=A[i][j];
        GetCorner(sz.a ,n/2+1);
        for(i=0;i<=n/2;i++)
            for(j=n/2;j<=n-1;j++)
                sz.b [i][j-n/2]=A[i][j];
        GetCorner(sz.b ,n/2+1);
        for(i=n/2;i<=n-1;i++)
            for(j=0;j<=n/2;j++)
                sz.c [i-n/2][j]=A[i][j];
        GetCorner(sz.c ,n/2+1);
        for(i=n/2;i<=n-1;i++)
            for(j=n/2;j<=n-1;j++)
                sz.d [i-n/2][j-n/2]=A[i][j];
        GetCorner(sz.d ,n/2+1);
        n/=2;
    }
    return 0;
}
int main()
{
    int  i,j,t,n;//n<=100
    int  Matrix[100][100];
    while(scanf_s("%d",&n)){
        if(n!=1){
            t=1;
            pass=0;
            if(n%2!=0){
                for(i=0;i<n;i++){
                    for(j=0;j<n;j++)
                        Matrix[i][j]=t++;
                }
                GetCorner(Matrix,n);
                Div_and_Put_Array(Matrix,n);
            }
            else
                printf("Can't get any square(s)!try another number!\n");
        }
        else
            printf("Can't get any square(s)!try another number!\n");
    }
    return 0;
}
搜索更多相关主题的帖子: 代码 
2010-07-25 16:49
xiayizhanzyf
Rank: 2
等 级:论坛游民
帖 子:80
专家分:78
注 册:2010-7-21
收藏
得分:5 
#include<stdio.h>
int pass;
typedef struct Corner
{
    int a;
    int b;
    int c;
    int d;
}Corner;
typedef struct Array
{
    int a[100][100];
    int b[100][100];
    int c[100][100];
    int d[100][100];
}Array;
int GetCorner(int m[100][100],int n)
{
    int flag=0,mid=n/2+1;
    if(n%2!=0){
        if(mid%2!=0 || pass==0){
            if(flag++==0){
                Corner corner;
                corner.a =m[0][0];
                corner.b =m[0][n-1];
                corner.c =m[n-1][0];
                corner.d =m[n-1][n-1];
                printf("%d %d %d %d\n",corner.a,corner.b,corner.c,corner.d);
            }
            if(flag++==1){
                Corner corner;
                corner.a =m[0][0];
                corner.b =m[0][mid-1];
                corner.c =m[mid-1][0];
                corner.d =m[mid-1][mid-1];
                printf("%d %d %d %d\n",corner.a,corner.b,corner.c,corner.d);

            }
            if(flag++==2){
                Corner corner;
                corner.a =m[0][mid-1];
                corner.b =m[0][mid*2-2];
                corner.c =m[mid-1][mid-1];
                corner.d =m[mid-1][mid*2-2];
                printf("%d %d %d %d\n",corner.a,corner.b,corner.c,corner.d);
            }
            if(flag++==3){
                Corner corner;
                corner.a =m[mid-1][0];
                corner.b =m[mid-1][mid-1];
                corner.c =m[mid-1][0];
                corner.d =m[mid*2-2][mid-1];
                printf("%d %d %d %d\n",corner.a,corner.b,corner.c,corner.d);
            }
            if(flag++==4){
                Corner corner;
                corner.a =m[mid-1][mid-1];
                corner.b =m[mid-1][mid*2-2];
                corner.c =m[mid*2-2][mid-1];
                corner.d =m[mid*2-2][mid*2-2];
                printf("%d %d %d %d\n",corner.a,corner.b,corner.c,corner.d);
            }
        }
    }
    return 0;
}
int Div_and_Put_Array(int A[100][100],int n)
{
    Array sz;
    int i,j;
    while(n/2>1){
        for(i=0;i<=n/2;i++)
            for(j=0;j<=n/2;j++)
                sz.a [i][j]=A[i][j];
        GetCorner(sz.a ,n/2+1);
        for(i=0;i<=n/2;i++)
            for(j=n/2;j<=n-1;j++)
                sz.b [i][j-n/2]=A[i][j];
        GetCorner(sz.b ,n/2+1);
        for(i=n/2;i<=n-1;i++)
            for(j=0;j<=n/2;j++)
                sz.c [i-n/2][j]=A[i][j];
        GetCorner(sz.c ,n/2+1);
        for(i=n/2;i<=n-1;i++)
            for(j=n/2;j<=n-1;j++)
                sz.d [i-n/2][j-n/2]=A[i][j];
        GetCorner(sz.d ,n/2+1);
        n/=2;
    }
    return 0;
}
int main()
{
    int  i,j,t,n;//n<=100
    int  Matrix[100][100];
    while(scanf("%d",&n)){
        if(n!=1){
            t=1;
            pass=0;
            if(n%2!=0){
                for(i=0;i<n;i++){
                    for(j=0;j<n;j++)
                        Matrix[i][j]=t++;
                }
                GetCorner(Matrix,n);
                Div_and_Put_Array(Matrix,n);
            }
            else
                printf("Can't get any square(s)!try another number!\n");
        }
        else
            printf("Can't get any square(s)!try another number!\n");
    }
    return 0;
}
2010-07-25 18:33
灬xiaoning
Rank: 2
等 级:论坛游民
帖 子:27
专家分:10
注 册:2010-7-24
收藏
得分:0 
回复 2楼 xiayizhanzyf
为什么我打7*7就错误了呢
2010-07-25 19:04
yjchaos
Rank: 2
等 级:论坛游民
帖 子:16
专家分:36
注 册:2010-7-4
收藏
得分:5 
你为什么要输入7*7呢,输入7*7真正输入的只有7,还有你的程序是做什么的,注释一下
2010-07-25 20:20
灬xiaoning
Rank: 2
等 级:论坛游民
帖 子:27
专家分:10
注 册:2010-7-24
收藏
得分:0 
回复 4楼 yjchaos
打印 我上面的题的四个角值
2010-07-25 21:26
快速回复:谁可以帮我改一下代码 代码如下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017323 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved