P4327 彼得潘框架

题意翻译

“彼得·潘框架”是一种装饰文字,每一个字母都是由一个菱形框架。一个彼得·潘框架看起来像这样 (x是字母,#是框架):

..#..
.#.#.
#.X.#
.#.#.
..#..

然而,只是一个框架会有些沉闷,所以我们每遇到三个字母会把第三个字母用温迪框架把它框起来。温迪框架看起来像这样:

..*..
.*.*.
*.X.*
.*.*.
..*..

当温迪和彼得·潘的框架重叠时,温迪框架覆盖在上面。 (见样例3和4)

输入格式: 一行包含至多15个英文字母的大写字母。

输出格式: 输出使用彼得·潘和温迪框架写成的5行文字。

题目描述

“Peter Pan frames” are a way of decorating text in which every character is framed by a diamond shaped frame, with frames of neigbhouring characters interleaving. A Peter Pan frame for one letter looks like this ('X' is the letter we are framing):

..#..
.#.#.
#.X.#
.#.#.
..#..

However, such a framing would be somewhat dull so we'll frame every third letter using a “Wendyframe”. A Wendy frame looks like this:

..*..
.*.*.
*.X.*
.*.*.
..*..

When a Wendy frame interleaves with a Peter Pan frame, the Wendy frame (being much nicer) is put on top. For an example of the interleaving check the sample cases.

输入输出格式

输入格式:

The first and only line of input will contain at most 15 capital letters of the English alphabet.

输出格式:

Output the word written using Peter Pan and Wendy frames on 5 lines.

输入输出样例

输入样例#1:
A
输出样例#1:
..#..
.#.#.
#.A.#
.#.#.
..#..
输入样例#2:
DOG
输出样例#2: 
..#...#...*..
.#.#.#.#.*.*.
#.D.#.O.*.G.*
.#.#.#.#.*.*.
..#...#...*..
输入样例#3: 
ABCD
输出样例#3: 
..#...#...*...#..
.#.#.#.#.*.*.#.#.
#.A.#.B.*.C.*.D.#
.#.#.#.#.*.*.#.#.
..#...#...*...#..

https://www.luogu.org/problemnew/show/P4327

#include<iostream>
#include<cstring>
using namespace std;

char a[6][62];
string s;

void frame(char c,int col,char flag)
{
    a[3][col]=c;
    // 第1行与第5行一样,所以a[1][col]=a[5][col]
    // 第2行关于col列对称,且与第4行一样。所以a[2][col+1]=a[r][col+1]=a[4][col-1]=a[2][col-1]
    // 第3行关于col列对称,所以a[3][col+2]=a[3][col-2]
    a[1][col]=a[2][col+1]=a[3][col+2]=a[4][col+1]=a[5][col]=a[4][col-1]=a[3][col-2]=a[2][col-1]=flag;
}

int main()
{
    memset(a,'.',sizeof(a));
    cin>>s;
    int n = s.size();
    
    // 注意观察第一行#或*出现的位置是4*i+3
    for(int i=0;i<n;i++)
    {
        // '*'先不画上
        if(i%3==2)
        {
            continue;
        }
        frame(s[i],4*i+3,'#');
    }

    for(int i=2;i<n;i+=3)
    {
        // 画上'*',若遇'#'直接覆盖
        frame(s[i],4*i+3,'*');
    }

    for(int i=1;i<6;i++)
    {
        for(int j=1;j<4*n+2;j++)
        {
            cout<<a[i][j];
        }
        cout<<endl;
    }

    return 0;
}
View Code

猜你喜欢

转载自www.cnblogs.com/alan-blog-TsingHua/p/10865484.html