哈理工OJ 1045 Draw A Square(简单模拟)

题目链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1045

Draw A Square
Time Limit: 1000 MS Memory Limit: 65536 K
Total Submit: 188(93 users) Total Accepted: 112(89 users) Rating: Special Judge: No
Description
Avery boring day, so Charlie decides to play a very simple game.
Hewould like to draw a square, instead of those squares filled with 0or 1, he wants to use his domain (5ushare) as the basicelements.
Following is the rules:

1.You should fill the edges with Letters repeatedly
2.You should fill the space with the digit 5
3.You should begin from left to right
4.You should begin from top to bottom
5.In a direction, you should filled the edge with the domain letters repeatedly, and also orderly
So,when n = 6, the square is just likethis:
ushare
s5555u
h5555s
a5555h
r5555a
eushar

Input
Eachline is a case, only a number, n is the length of theedge,0 < n < 100

Output
the square thatwill meet the demands. After each case, output a blank line.

Sample Input
1
2
3
6

Sample Output
u

us
sh

ush
s5a
har

ushare
s5555u
h5555s
a5555h
r5555a
eushar

Hint
1.You could file the edges in the order of up edge, left edge, downedge, and at last the right edge.
2.The first letter of up edge is ‘u’, and the first letter of other edge wile be decided by its previous edge.

【中文题意】给你一个整数n,然后让你画一个长度为n的方阵,画方阵的规则如下:从左到右“ushare”从上到下”ushare” 以此重复,最下面一行从左到右也是按照”ushare”的顺序来,最后一列同最后一行。
【思路分析】直接模拟,但是不要忘了’\0’,被’\0’坑了一发。
【AC代码】

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

char str[10]="ushare";
char a[105][105];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        if(n==1)
        {
            printf("u\n");
        }
        else if(n==2)
        {
            printf("us\n");
            printf("sh\n");
        }
        else
        {
            for(int i=0;i<n;i++)
            {
                a[0][i]=str[i%6];
                a[i][0]=str[i%6];
            }
            for(int i=1;i<n-1;i++)
            {
                for(int j=1;j<n-1;j++)
                {
                    a[i][j]='5';
                }
            }
            int x=(n-1)%6;
            for(int i=1;i<n;i++)
            {
                a[n-1][i]=str[(x+i)%6];
                a[i][n-1]=str[(x+i)%6];
            }
            for(int i=0;i<n;i++)
            {
                a[i][n]='\0';
                printf("%s\n",a[i]);
            }
        }
        printf("\n");
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值