替代*和#模式 [英] Alternate * and # pattern

查看:77
本文介绍了替代*和#模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写程序以在*和#中打印备用模式。



输入为:包含整数的一行,N。



输出为:要打印的'*'和'#'图案的替代模式。





例如:



输入:输出



1 *



5 * ####

### **

*** ##

### **

* ####



8 * #######

## #### **

*** #####

#### ****

**** ####

##### ***

** ######

####### *



我有什么尝试过:



我试过解决它但仍然没有成功解读#和*的代码如何传播。



所以,如果可以,请帮助我,我应该怎么理解它!



谢谢。



对不起问题。

Write a Program to print the Alternate Pattern in * and #.

Input as: One Line Containing an Integer,N.

Output as: An Alternate pattern of '*' and '#' patterns to be Printed.


Example:

Input: Output

1 *

5 *####
###**
***##
###**
*####

8 *#######
######**
***#####
####****
****####
#####***
**######
#######*

What I have tried:

I did Tried to solve it but Still I am Unsuccessful in deciphering how the code of # and * propagates over.

So, Help me if you can as how should i Understand it!

Thanks.

Sorry for the Blunt Question.

推荐答案

您需要先提示用户并从他那里读取一个号码 - > N

然后,你需要打印那行数。

在循环之前,以星数为1开始,哈希计数为N - 1

循环内部,检查行号是奇数还是偶数(提示:和它一起。如果那是零,那就是偶数)

奇数:打印星星计数星星,然后哈希计数哈希。

偶数:打印奇数:打印哈希计数哈希,然后星星计数星星

增加星数,并减少哈希计数

转到下一行。



但这是你的功课,所以没有代码!
You need to start by prompting the user and reading a number from him -> N
Then, you need to print that number of lines.
Before the loop, start with a "stars count" of 1, and a "hashes count" of N - 1
inside the loop, check if the line number is odd or even (Hint: AND it with one. If that's zero, it's even)
Odd: Print "stars count" stars, then "hashes count" hashes.
Even: Print Odd: Print "hashes count" hashes, then "stars count" stars
Increment "stars count",and decrement "hashes count"
Go round for the next line.

But this is your homework, so no code!


我们不做你的HomeWork。

HomeWork不会测试你的技能,乞求别人做你的工作,它会帮助你的老师检查您对所学课程的理解以及您应用这些课程时遇到的问题。

你的任何失败都会帮助你的老师发现你的弱点并设定补救措施。

所以,试一试,重读你的课程并开始工作。如果您遇到特定问题,请显示您的代码并解释这个问题,我们可能会提供帮助。

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
Quote:

那不是我的功课。

我在解决在线测验代码时得到了它而我无法做到。

That's not my homework.
I got it while solving an online quiz code and I couldn't do it.

这是HomeWork,因为它对于新手学生来说很复杂,它是旨在教你如何结合事物。



建议:

拿一张纸并制作一张表格,你可以在列中报告事实。

- 行号

- 行号是奇数甚至是

- 行上有多少颗星

- 多少#在线

- 从左或右开始

将此表格设为8和9,然后查找模式。



训练:

问一个数字,然后画出一些东西:

-画一个三角形

*

* *

* * *

* * * *

* * * * *

-Add#使其成为正方形

* ####

* * ###

* * * ##

* * * *#

* * * * *

-Swap left-right

####

# ## * *

## * * *

#* * * *

* * * * *

-画一个金字塔

*

* *

* * *

* *

*

-Add#使它成为一个正方形

* ####

* * ###

* * * ##

* * ###

* ####

-Swap left-right

####

### * *

## * * *

### * *

#### *



作为程序员,数学也很放心

检查行为绝对函数

对于x = -2,-1,0,1和2:

abs(x)的结果是什么

结果是什么 3-abs(x)

与其他模式。

It is HomeWork because it is complicated only for newbie student, it is aimed to teach you how to combine things.

Advice:
Take a sheet of paper and make a table where you report facts in columns.
- line number
- line number is odd or even
- how many stars on the line
- how many # on the line
- starts on left or right
Make this table for 8 and 9, then look for patterns.

Training exercises:
Ask a number, then draw something:
-Draw a triangle
*
* *
* * *
* * * *
* * * * *
-Add # to make it a square
* # # # #
* * # # #
* * * # #
* * * * #
* * * * *
-Swap left-right
# # # # *
# # # * *
# # * * *
# * * * *
* * * * *
-Draw a pyramid
*
* *
* * *
* *
*
-Add # to make it a square
* # # # #
* * # # #
* * * # #
* * # # #
* # # # #
-Swap left-right
# # # # *
# # # * *
# # * * *
# # # * *
# # # # *

Being a programmer is also being at ease with mathematics
Check the behavior of the absolute function
For x= -2, -1, 0, 1 and 2 :
what is the result of abs(x)
what is the result of 3-abs(x)
Compare with the other patterns.


虽然看起来最像已经在其他解决方案中回答了这些问题,这里有一些关于如何破译确定输出的算法的更一般的建议。



你必须调查所有的例子到认识到这种模式。最长的例子(在这种情况下对于输入8)通常将提供最多的信息。如果您认为可以发现最长模式的属性,可以查看其他示例,看看您的猜想是否成立。



然后你可以检查模式是如何依赖的在输入值上。同样,如果您认为可以发现依赖关系,请检查所有示例以确定您是否正确。



您找到的每个属性和依赖关系都可以是翻译成规则并纳入您的计划。根据模式的复杂程度,可能需要很多规则。如果您认为自己已找到所有内容,则可以尝试完成您的计划。但是,如果您发现您的程序缺少正确重现模式的信息,您可能错过了规则,您需要再次检查示例。



或者您可以开始编写程序,并在此过程中,考虑重现每行输出所需的信息量和信息量。 E. g。您需要打印多少行,每个输出行有多长,特定行包含什么等等。然后您可以在示例中查找特定信息的线索。
While it seems most aspects are being answered in the other solutions already, here's some more general advice on how to decipher the algorithm that determines the output.

You have to investigate all the examples to recognize the pattern. The longest example (in this case for the input 8) will typically provide the most information. If you think you can spot a property of the longest pattern, you can check the other examples to see if your conjecture holds.

Then you can check how the patterns depend on the input value. Again, if you think you can spot a dependency, check all examples to find out if you're right.

Each of the properties and dependencies that you found can be translated into a rule and incorporated into your program. Depending on the complexity of the pattern, it may require a lot of rules. If you think you've found them all, you can try to complete your program. However, if you find that your program is lacking information to correctly reproduce the patterns, you probably missed a rule and you need to check the examples again.

Alternately you can start writing your program and, while doing so, consider how much and what information you may need to reproduce each line of output. E. g. how many lines do you need to print, how long is each output line, what does a particular line consist of, etc.. Then you can look for clues on that specific information in the examples.


这篇关于替代*和#模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆