加载中...

画图题

输入n画这样的图

n=2
\ | /
|/
--O--
/|
/ |
n=5
\ | / 空格0 斜线 空格4 竖线 空格4
\ | / 空格1 斜线 空格3 竖线 空格3
\ | /
\ | /
|/空格4 斜线 空格0 竖线 空格4
-----O-----
/|
/ |
/ |
/ |
/ | \

int main()
{
    int n;
    cin >> n;
    for(int i=n;i > 0 ;i--)
    {
        for(int k=1;k<=n-i;k++)
        {
            cout << " ";
        }
        cout << "\\";
        for(int j=i-1;j;j--)
        {
            cout << " ";
        }
        cout << "|";
        for(int j=i-1;j;j--)
        {
            cout << " ";
        }
        cout << "/" ;
        cout << endl ;
    }
//中间根据n判断 
    for(int i=1 ;i<=n ;i++)
    {
        cout << "-";
    }
    cout << "O" ;
    for(int i=1 ;i<=n ;i++)
    {
        cout << "-";
    }
    cout << endl;
    for(int i=1;i <= n ;i++)
    {
        for(int k=1;k<=n-i;k++)
        {
            cout << " ";
        }
        cout << "/";
        for(int j=i-1;j;j--)
        {
            cout << " ";
        }
        cout << "|";
        for(int j=i-1;j;j--)
        {
            cout << " ";
        }
        cout << "\\" ;
        cout << endl ;
    }
    return 0;
}

镜像翻转 (找到 反转之后i 和 j 坐标的规律)
字符串数组vector a(n), b(n);

ij坐标从0开始 !
void turn90(vector<string> &g) //旋转90度
{
    vector<string> t = g;
    for (int i = 0; i < n; i ++ )
        for (int j = 0; j < n; j ++ )
            t[j][n - 1 - i] = g[i][j];//从0开始 开局自带n-1 
    g = t;
}

// 将矩阵镜像翻转 
void mirror(vector<string> &g)//镜面翻转
{
    vector<string> t = g;
    for (int i = 0; i < n; i ++ )
        for (int j = 0; j < n; j ++ )
            t[i][j] = g[i][n - 1 - j];
    g = t;
}



擅长c https://www.acwing.com/activity/content/problem/content/7072/

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

char g[26][7][6];//字母  行 列
bool is_first = true;

void output(string word)
{
    if (word.empty()) return;

    if (is_first) is_first = false;//第一行的上面 不需要空格
    else cout << endl;

    char str[7][60] = {0};//要输出的一个的单词
    for (int i = 0; i < word.size(); i ++ )
        for (int j = 0; j < 7; j ++ )
            for (int k = 0; k < 5; k ++ )
                str[j][i * 6 + k] = g[word[i] - 'A'][j][k];//第j行第k列字符

    for (int i = 1; i < word.size(); i ++ )
        for (int j = 0; j < 7; j ++ )
            str[j][i * 6 - 1] = ' ';//填空格

    for (int i = 0; i < 7; i ++ )
        cout << str[i] << endl;//输出每行
}

int main()
{
    for (int i = 0; i < 26; i ++ )
        for (int j = 0; j < 7; j ++ )
            cin >> g[i][j];//输入字符串

    string word;
    char c;
    while ((c = getchar()) != -1)
    {
        if (c >= 'A' && c <= 'Z') word += c;
        else
        {
            output(word);//输入单词
            word = "";
        }
    }

    output(word);

    return 0;
}

posted @ 2022-02-04 15:43  liang302  阅读(87)  评论(0编辑  收藏  举报