2574 - Val 1: Difference between revisions

From Bitnami MediaWiki
Paul Ungur (talk | contribs)
Paul Ungur (talk | contribs)
Line 16: Line 16:


Ieșire
Ieșire
__0_0_____0_0_____0_0_____0_0___
__0_0_____0_0_____0_0_____0_0___
_0___0___0___0___0___0___0___0__
_0___0___0___0___0___0___0___0__
_0___0___0___0___0___0___0___0__
_0___0___0___0___0___0___0___0__
_0___0___0___0___0___0___0___0__
_0___0___0___0___0___0___0___0__
0_____0_0_____0_0_____0_0_____0_
0_____0_0_____0_0_____0_0_____0_


Exemplul 2:
Exemplul 2:
Intrare
Intrare
6 8
6 8


Ieșire
Ieșire
__0_0_____0_0_____0_0_____0_0_____0_0_____0_0_____0_0_____0_0___
__0_0_____0_0_____0_0_____0_0_____0_0_____0_0_____0_0_____0_0___
_0___0___0___0___0___0___0___0___0___0___0___0___0___0___0___0__
_0___0___0___0___0___0___0___0___0___0___0___0___0___0___0___0__
_0___0___0___0___0___0___0___0___0___0___0___0___0___0___0___0__
_0___0___0___0___0___0___0___0___0___0___0___0___0___0___0___0__
_0___0___0___0___0___0___0___0___0___0___0___0___0___0___0___0__
_0___0___0___0___0___0___0___0___0___0___0___0___0___0___0___0__
_0___0___0___0___0___0___0___0___0___0___0___0___0___0___0___0__
_0___0___0___0___0___0___0___0___0___0___0___0___0___0___0___0__
0_____0_0_____0_0_____0_0_____0_0_____0_0_____0_0_____0_0_____0_
0_____0_0_____0_0_____0_0_____0_0_____0_0_____0_0_____0_0_____0_


==Rezolvare==
==Rezolvare==
<syntaxhighlight lang=“python” line>
<syntaxhighlight lang="python" line="1">
n, m = map(int, input().split())
n, m = map(int, input().split())



Revision as of 19:40, 19 March 2023

Cerința

Se citeste n și m. Să se reprezinte următoarea diagramă în funcție de n și m, în care n reprezintă înălțimea, iar m numărul de valuri care compun diagrama. Diagrama este formată din caractere 0, interiorul și exteriorul valurilor sunt alcătuite din caractere _.

Date de intrare

Programul citește numerele n m.

Date de ieșire

Programul va afișa o diagrama cerută.

Restricții și precizări

1 ≤ n ≤ m ≤ 20

Exemplul 1:

Intrare 5 4

Ieșire

__0_0_____0_0_____0_0_____0_0___

_0___0___0___0___0___0___0___0__

_0___0___0___0___0___0___0___0__

_0___0___0___0___0___0___0___0__

0_____0_0_____0_0_____0_0_____0_

Exemplul 2:

Intrare

6 8

Ieșire

__0_0_____0_0_____0_0_____0_0_____0_0_____0_0_____0_0_____0_0___

_0___0___0___0___0___0___0___0___0___0___0___0___0___0___0___0__

_0___0___0___0___0___0___0___0___0___0___0___0___0___0___0___0__

_0___0___0___0___0___0___0___0___0___0___0___0___0___0___0___0__

_0___0___0___0___0___0___0___0___0___0___0___0___0___0___0___0__

0_____0_0_____0_0_____0_0_____0_0_____0_0_____0_0_____0_0_____0_

Rezolvare

<syntaxhighlight lang="python" line="1"> n, m = map(int, input().split())

for i in range(n):

   for j in range(m):
       if i == 0 or i == n - 1:
           if j % 2 == 0:
               print("_", end="")
           else:
               print("0", end="")
       elif i % 2 != 0:
           if j == 0 or j == m - 1:
               print("0", end="")
           elif j % 2 != 0:
               print("_", end="")
           else:
               print("0", end="")
       else:
           print("_", end="")
   print()

</syntaxhighlight>