| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 277 人关注过本帖
标题:关于矩阵的问题。
只看楼主 加入收藏
hsmile
Rank: 1
来 自:大连
等 级:新手上路
帖 子:23
专家分:0
注 册:2009-5-21
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:1 
关于矩阵的问题。
有个M*N的矩阵,用26个字母按这个顺序填充。
ABCDEFGH
TUVWXYZI
SFEDCBAJ
RQPONMLK
就是从外往里转,其中M和N的值由键盘输入。
根据输入的M和N值不同,矩阵有不同的样子。
搜索更多相关主题的帖子: 矩阵 
2010-04-10 15:55
ldg628
Rank: 12Rank: 12Rank: 12
等 级:火箭侠
威 望:3
帖 子:526
专家分:3036
注 册:2009-6-23
收藏
得分:10 
#include <stdio.h>
#include <stdlib.h>

int M, N;
void fun(char *p, int m, int n, int c)
{
    int i;
    for (i = 0; i < n; i ++)
    {
        p[i] = 'A' + (c++)%26;
    }
    for (i = 1; i < m; i ++)
    {
        p[i*N+n-1] = 'A' + (c++)%26;
    }
    for (i = n-2; i > 0; i --)
    {
        if (m == 1) break;
        p[(m-1)*N+i] = 'A' + (c++)%26;
    }
    for (i = m-1; i > 0; i --)
    {
        if (n == 1) break;
        p[i*N] = 'A' + (c++)%26;
    }
    m -= 2;
    if (m<=0) return;
    n -= 2;
    if (n<=0) return;
    p = p + N+1;
    fun(p, m, n, c);
}
int main(void)
{                                                                                                                 
    int i, j;                                                                                                     
    char *p;                                                                                                      
                                                                                                                  
    scanf("%d%d", &M, &N);                                                                                       
    p =  (char *)malloc(M*N*sizeof(char));                                                                        
                                                                                                                  
    fun(p, M, N, 0);                                                                                             
    for (i = 0; i < M; i ++)                                                                                      
    {                                                                                                            
        for (j = 0; j < N; j ++)                                                                                 
        {                                                                                                         
            printf("%c", *(p+N*i+j));                                                                             
        }                                                                                                         
        printf("\n");                                                                                             
    }                                                                                                            
    free(p);                                                                                                      
}              
办法是比较土,但能出结果。。。囧,楼主再测一测吧,看看有没有没有照顾到的情况
2010-04-10 17:41
快速回复:关于矩阵的问题。
数据加载中...
 
   



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

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