zoukankan      html  css  js  c++  java
  • 打印十字图

    问题描述

    小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示:

    对方同时也需要在电脑dos窗口中以字符的形式输出该标志,并能任意控制层数。

    输入格式
    一个正整数 n (n<30) 表示要求打印图形的层数。
    输出格式
    对应包围层数的该标志。
    样例输入1
    1
    样例输出1
    样例输入2
    3
    样例输出2
    提示
    请仔细观察样例,尤其要注意句点的数量和输出位置。
     
    #include <iostream>
    #include <cstdio>
    #include <stdio.h>
    #include <vector>
    #include <algorithm>
    #include <stdlib.h>
    #include <string.h>
    #include <cmath>
    #include <string>
    #include <fstream>
    using namespace std;
    int hoge(int x,int y,int n){
        if(x == 2*(n+1) && y <=2*n)//第一排 
            return 1;
        else if(x == 2*n+1 && y == 2*n)//第二排 
            return 1;
        else if(x < 2*n && y== 2*(n+1)) //四周边框 
            return 1;
        else if(x ==0 && y==0)//图形中心 
            return 1;
        else if(x==2*n && (y==2*(n+1)||y==2*(n+1)-1||y==2*(n+1)-2))//第三排 
            return 1;
        return 0;
    }
    int main(){
        int n;
        cin>>n;
        int x = 2*(n+1);//x
        for(int i=0;i<4*n+5;i++){
            for(int j=0;j<4*n+5;j++){
                int k;
                for(k = 0;k<=n;k++)
                    if(hoge(abs(x-i),abs(x-j),k)==1){
                        cout<<'$';
                        break;
                    }
                if(k == n+1)
                    cout<<'.';
            }
            cout<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Unstar A File:
    star 一个文件
    列出大星号文件
    删除用户
    curl -d
    创建用户
    Check Account Info
    List Accounts
    认证ping
    python 解接口返回的json字符串
  • 原文地址:https://www.cnblogs.com/woxiaosade/p/10316348.html
Copyright © 2011-2022 走看看