目录
AC code
题目描述
“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.
题意翻译
“彼得·潘框架”是一种装饰文字,每一个字母都是由一个菱形框架。一个彼得·潘框架看起来像这样 (x是字母,#是框架):
..#.. .#.#. #.X.# .#.#. ..#..
然而,只是一个框架会有些沉闷,所以我们每遇到三个字母会把第三个字母用温迪框架把它框起来。温迪框架看起来像这样:
..*.. .*.*. *.X.* .*.*. ..*..
当温迪和彼得·潘的框架重叠时,温迪框架覆盖在上面。 (见样例3和4)
输入格式: 一行包含至多15个英文字母的大写字母。
输出格式: 输出使用彼得·潘和温迪框架写成的5行文字。
输入输出格式
输入格式
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.
输入输出样例
输入
ABCD
输出
..#...#...*...#.. .#.#.#.#.*.*.#.#. #.A.#.B.*.C.*.D.# .#.#.#.#.*.*.#.#. ..#...#...*...#..
AC code
#include <bits/stdc++.h>//万能头,好东西
using namespace std;
int len,lena,ll=3,aa;//ll为第一个字母的初始位置
char a[20],b[1000][100],c;
int main(){cin>>a;//输入初始字符串len=strlen(a);//求出字符串长度,strlen()函数能求出字符串长度lena=4*len+1;//求出输出字符矩阵的长度,宽度恒为五memset(b,'.',sizeof(b));//将b数组全赋值为‘.’,以便后来使用while(ll<=lena){//开始循环aa++;//到第aa个字母if(aa%3==0)c='*';else c='#';//若为3的倍数个,则用‘*’b[3][ll]=a[aa-1];//把字母填入b数组中b[1][ll]=c;b[5][ll]=c;b[2][ll-1]=c;b[2][ll+1]=c;b[4][ll-1]=c;b[4][ll+1]=c;//根据字母的位置推出其他字符的位置,并填入b数组中if(b[3][ll-2]!='*')b[3][ll-2]=c;if(b[3][ll+2]!='*')b[3][ll+2]=c;//特判,若以被‘*’覆盖,则不能被‘#’覆盖ll+=4;//之后每个字母的为止为前一个加4}for(int i=1;i<=5;i++){for(int j=1;j<=lena;j++)cout<<b[i][j];//输出cout<<endl;//不要忘了每行要加回车}return 0;//end
}