方框

描述

用'*'打印出一个nxn的字符图形(1<=n<=100).

输入

多组输入。每行输入一个n,输入EOF结束文件.

输出

输出一个满足题意的图形.

输入样例 1 

1
2
5
6
10
11

输出样例 1

*
**
**
*****
* *
* * *
* *
*****
******
* *
* ** *
* ** *
* *
******
**********
* *
* ****** *
* * * *
* * ** * *
* * ** * *
* * * *
* ****** *
* *
**********
***********
* *
* ******* *
* * * *
* * *** * *
* * * * * *
* * *** * *
* * * *
* ******* *
* *
***********

思路

就是按照给出的样例找规律,然后n*n的图形

可以明显的看出,这个图形的特点是一圈被全是*,一圈全是空白。发现了这个规律的话可以用模拟来做(学长和一些用模拟AC的大佬说的,但是感觉模拟好麻烦,不太好写)

再仔细观察可以发现:这个图形是个对称的(废话)。然后从第三行开始往后,每一行都是根据上上一行的字符串复制过来,然后将上上一行的连在一起的空格或者*的第二个和倒数第二个给改变(*变成空格,空格变成*)。最后输出的时候判断奇偶,对称输出就可以了

AC代码

#include<bits/stdc++.h>
#define ll long long
#define ms(a) memset(a,0,sizeof(a))
using namespace std;
const int maxn=1e6+10;
char ch[110][110];
int main()
{
ios::sync_with_stdio(false);
int n;
while(cin>>n)
{
if(n==1)
{
cout<<"*"<<endl;
continue;
}
if(n==2)
{
for(int i=1;i<=2;i++)
cout<<"**"<<endl;
continue;
}
ms(ch);
int res=(n+1)/2;
int cnt=2;
for(int i=1;i<=res;i++)
{
if(i==1)
{
for(int j=1;j<=n;j++)
ch[i][j]='*';
}
if(i==2)
{
ch[i][1]='*';
ch[i][n]='*';
for(int j=2;j<n;j++)
ch[i][j]=' ';
}
if(i>2&&i%2)
{
// 本来是用strcmp来复制的,但是好像二维的字符串函数不能用,复制出来的全是空行
for(int k=1;k<=n;k++)
{
ch[i][k]=ch[i-2][k];
}
ch[i][cnt]=' ';
ch[i][n-cnt+1]=' ';
cnt++;
}
if(i>2&&i%2==0)
{
for(int k=1;k<=n;k++)
{
ch[i][k]=ch[i-2][k];
}
ch[i][cnt]='*';
ch[i][n-cnt+1]='*';
cnt++;
}
}
for(int i=1;i<=res;i++)
{
for(int j=1;j<=n;j++)
cout<<ch[i][j];
cout<<endl;
}
if(n%2)
{
for(int i=res-1;i>=1;i--)
{
for(int j=1;j<=n;j++)
cout<<ch[i][j];
cout<<endl;
}
}
else
{
for(int i=res;i>=1;i--)
{
for(int j=1;j<=n;j++)
cout<<ch[i][j];
cout<<endl;
}
}
}
return 0;
}

HPU第四次积分赛-K :方框(水题,打印图形)的更多相关文章

  1. HPU第四次积分赛-L:A Winged Steed(完全背包)

    A Winged Steed 描述 有n种千里马,每一种都有若干匹,第i种马的颜值ai​,价格di​.现有m个牧马人要去挑选千里马,每一位牧马人对马的颜值都有要求:{所选马的颜值总和} ⩾Ai​.现在 ...

  2. HPU 第三次积分赛:阶乘之和(水题)

    阶乘之和 描述 对于整数pp,给出以下定义 p=x_{1}!+x_{2}!+x_{3}!+...+x_{q}!(x_{i}<x_{j}for\ all\ i<j )p=x1​!+x2​!+ ...

  3. CF451C Predict Outcome of the Game 水题

    Codeforces Round #258 (Div. 2) Predict Outcome of the Game C. Predict Outcome of the Game time limit ...

  4. 没讲明白的水题orz

    有一道解释程序的水题没给非计算机专业的同学讲明白orz,在这里再练一下.. 源代码完全没有缩进真是难以忍受.. p.s.懂递归就不用看了#include <stdio.h> int n = ...

  5. POJ 水题(刷题)进阶

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

  6. Atcoder 水题选做

    为什么是水题选做呢?因为我只会水题啊 ( 为什么是$Atcoder$呢?因为暑假学长来讲课的时候讲了三件事:不要用洛谷,不要用dev-c++,不要用单步调试.$bzoj$太难了,$Topcoder$整 ...

  7. HDU - 1716 排列2 水题

    排列2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  8. hdu 2025:查找最大元素(水题,顺序查找)

    查找最大元素 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  9. #82. 【UR #7】水题生成器

    链接:http://uoj.ac/problem/82 今天是世界水日,著名的水题资源专家蝈蝈大臣向世界宣布了他的一项新发明 —— 水题生成器. 每道题目都有一个正整数的难度值.水题生成器虽然强大但是 ...

随机推荐

  1. JQuery进度条

    需要实现效果如下图. 页面代码<div class='progress_bar' data-color='#f66' data-per='"+list[i].percent+" ...

  2. ubuntu中更新.netcore到2.1版本

    如果需要安装新版本到dotnetcore,需要先卸载旧版本(https://github.com/dotnet/core/blob/master/release-notes/download-arch ...

  3. AI新建文件可以新建多个画板5.2

  4. unity中让摄像机移动到鼠标点击的位置和鼠标控制平移视角

    private Vector3 targetVector3; private float movespeed=0.5f; private bool IsOver = true; private Gam ...

  5. java串口编程

    报错:no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDrive java.lang.Unsatisfie ...

  6. 【资料收集】QT 环境安装配置

    (很详细,极力推荐) [OpenCV] -- win7下配置OpenCV的Qt开发环境 - 代码人生 - 博客频道 - CSDN.NET  http://blog.csdn.net/qiurisuix ...

  7. tomcat版本对应jee版本等信息

    可以参考官方: http://tomcat.apache.org/whichversion.html http://www.bubuko.com/infodetail-674892.html

  8. Android: apk反编译 及 AS代码混淆防反编译

    一.工具下载: 1.apktool(资源文件获取,如提取出图片文件和布局文件) 反编译apk:apktool d file.apk –o path 回编译apk:apktool b path –o f ...

  9. SQL-39 使用索引

    题目描述 针对salaries表emp_no字段创建索引idx_emp_no,查询emp_no为10005, 使用强制索引.CREATE TABLE `salaries` (`emp_no` int( ...

  10. Python 连接 redis 模块

    redis 模块使用可以分类为: 连接方式 连接池 操作 String操作 Hash操作 List操作 Set操作 Sort Set操作 管道 发布订阅 (1)操作模式 redis提供两个类Redis ...