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

来源:互联网 发布:nginx 图片服务器架构 编辑:程序博客网 时间:2024/04/19 13:58

题目链接: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;}
0 0
原创粉丝点击