您的位置:首页 > 移动开发 > IOS开发

简单的打印类题目,仅作为自己的记录.

2007-09-27 22:14 302 查看
[题目]

如下,最外层输出X,次外层输出Y,依次往里面输出0、1、2......
最简单的方法是什么?
                     X X X X X X X
                     X Y Y Y Y Y X
                     X Y 0 0 0 Y X
                     X Y 0 1 0 Y X
                     X Y 0 0 0 Y X
                     X Y Y Y Y Y X
                     X X X X X X X

[我的代码]


#include <math.h>


#include <iostream>


using namespace std;






char    gszData[] = ...{'X', 'Y', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};




int iMax(int a, int b)




...{


    return    a >b ? a : b;


}




void bMyShow(int iCount)




...{


    for (int i = 0; i < iCount * 2 - 1; i++)




    ...{


        for (int j = 0; j < iCount * 2 - 1; j++)




        ...{


            cout<<gszData[iCount - iMax(abs(iCount - i - 1), abs(iCount - j -1)) - 1]<<" ";


        }


        cout<<endl;


    }


}




int main(int argc, char* argv[])




...{


    bMyShow(7);


    return 0;


}



 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iostream math.h
相关文章推荐