当前位置: 首页 > news >正文

打印大X | 第六届蓝桥杯省赛C++C组

小明希望用星号拼凑,打印出一个大 X,他要求能够控制笔画的宽度和整个字的高度。

为了便于比对空格,所有的空白位置都以句点符来代替。

现在给定笔画的宽度和字的高度,请你将大 X 打印出来。

具体形式可参照下面样例。

输入格式

包含两个整数 m,nm,n,表示笔的宽度以及 X 的高度。

输出格式

参照样例形式,输出大 X。

数据范围

0<m<n0<m<n,
3<n<10003<n<1000,
nn 保证是一个奇数。

题解:

        发现确定m和n的时候,图片的长度是确定的:

wights=m+n-1

        同时,前面的点的个数是个等差数列,上半部分的长度达到了:

half=(n-3)/2

        然后遍历求解即可。 

代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<stack>
#include<vector>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<set>
using namespace std;
typedef long long int ll;
const int INF=1e16;

int m,n;

void solve(){
    cin >> m >> n;
    int wights=m+n-1;
    int half=(n-3)/2;
    //up
    for(int i=0;i<=half;i++){
        for(int j=0;j<i;j++){
            cout << '.';
        }
        for(int j=0;j<m;j++){
            cout << '*';
        }
        if(wights-i*2 < 2*m){
            for(int j=0;j<wights-2*i-m;j++){
                cout << '*';
            }
            for(int j=0;j<i;j++){
                cout << '.';
            }
        }
        else{
            for(int j=0;j<wights-2*i-2*m;j++){
                cout << '.';
            }
            for(int j=0;j<m;j++){
                cout << '*';
            }
            for(int j=0;j<i;j++){
                cout << '.';
            }
        }
        cout << "\n";
    }
    //mid
    for(int i=0;i<half+1;i++){
        cout << '.';
    }
    for(int i=0;i<m;i++){
        cout << '*';
    }
    for(int i=0;i<half+1;i++){
        cout << '.';
    }
    cout << "\n";
    //down
    for(int i=half;i>=0;i--){
        for(int j=0;j<i;j++){
            cout << '.';
        }
        for(int j=0;j<m;j++){
            cout << '*';
        }
        if(wights-i*2 < 2*m){
            for(int j=0;j<wights-2*i-m;j++){
                cout << '*';
            }
            for(int j=0;j<i;j++){
                cout << '.';
            }
        }
        else{
            for(int j=0;j<wights-2*i-2*m;j++){
                cout << '.';
            }
            for(int j=0;j<m;j++){
                cout << '*';
            }
            for(int j=0;j<i;j++){
                cout << '.';
            }
        }
        cout << "\n";
    }
}

int main(){
    solve();
}

http://www.dtcms.com/a/121744.html

相关文章:

  • TDengine 数据模型设计:多列模式与单列模式对比(二)
  • PowerBI之DAX 2:聚合、统计、关系、表操作函数
  • 力扣题解:142. 环形链表 II
  • 柳宗元经典的10首唐诗
  • 指定运行级别
  • 【补题】Educational Codeforces Round 150 (Rated for Div. 2) C. Ranom Numbers
  • 计算机中的单位
  • 基于php扩展加密的一个简单逆向
  • 深入 C++ 线程库:从创建到同步的探索之旅
  • 天基光学图像仿真原理简介
  • 一个很好用的vue2在线签名组件
  • 《系统分析师-基础篇-7-9章总结》
  • 嵌入式AI前沿:精选工具与应用网站解析
  • 25/4/9 算法笔记 DBGAN+强化学习+迁移学习实现青光眼图像去模糊1
  • CSS Grid布局:从入门到放弃再到真香
  • CF442A Borya and Hanabi
  • latex模板文件
  • VTK随笔十四:QT与VTK的交互示例(平移)
  • Docker多阶段构建深度优化指南:从GB到MB的镜像瘦身革命
  • 【C语言】浮点数在内存的储存
  • Element Plus 组件库二次封装在ZKmall商城的实践与沉淀
  • 2.4GHz射频前端噪声系数优化架构
  • 内存分配中的堆(Memory Heap)详解
  • C++类成员内存分布详解
  • Android 11 (API 30) 及更高版本中,查询的特定应用商店包,无需动态请求权限处理
  • MyBatis 详解及代码示例
  • 机器学习--数据填充
  • 楼宇自控系统构建机电设备管理新方式,提升建筑管理水平
  • 【C++进阶】关联容器:set类型
  • Python 3.x cxfreeze打包exe教程