哈理工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;}
- 哈理工OJ 1045 Draw A Square(简单模拟)
- 哈理工OJ 1031 _OOOO_ Problem(简单模拟问题)
- 哈理工OJ 2111 Apple(简单模拟)
- hrbust 哈理工oj 1020 Robot Motion【简单模拟】
- 哈理工OJ 1562 字符统计器(水模拟)
- hrbust 哈理工oj 1330 邂逅【模拟】
- 哈理工OJ 2033 A Funny Game(博弈问题)
- 哈理工 OJ 2215 Angle(简单的思维题)
- 哈理工OJ 2214 Judge(简单的数学题)
- 哈理工OJ 1124 Final Destination(简单递推)
- 哈理工OJ 1986 大悲咒(简单递推)
- 哈理工oj 1000 A+B problem
- 哈理工 1178 分数加减(简单的模拟)
- 哈理工OJ 1580 Tell me the length(模拟+找规律)
- 哈理工OJ 1020 Robot Motion(模拟+队列【类似小搜索】)
- 哈理工OJ 1176 小陈老师、雪人(排序+优先队列模拟)
- 哈理工OJ 1575 Calculate the day-1(水模拟)
- 哈理工OJ 2255 镇守府海域·镇守府近海(模拟题目)
- 帝国CMS常用标签
- linux读写mac HFS+
- 手机端通过软件Es文件浏览器访问Linux服务器文件(局域网或远程服务器)
- CSS学习笔记:排版布局属性
- JavaScript 中element和attribute以及节点、属性的增删
- 哈理工OJ 1045 Draw A Square(简单模拟)
- Linux中的高级文本处理命令,cut命令,sed命令,awk命令
- Zookeeper 配置文件解释
- 【浑水摸鱼】化学方程式默写练习器
- 算法训练 未名湖边的烦恼
- hdu 2087
- 使用TensorFlow编写识别数字的CNN训练程序详解
- 汇编语言----中断指令
- JavaScript求非空子集数目