Vydělávej až 160.000 Kč měsíčně! Akreditované rekvalifikační kurzy s garancí práce od 0 Kč. Více informací.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.

Diskuze: Pomoc se řešením úkolu v C#.NET?

Aktivity
Avatar
alexneti
Člen
Avatar
alexneti:9.4.2015 18:18

Ahoj,

nevíte někdo jak tohle vyřešit? Jsem na to narazil při testu a nějak nevím ... :)

Inverted pyramid of integer numbers is a pyramid of random numbers with the base being at the top. For example this is such a pyramid
1 7 12 3
10 4 1
20 22
10
Let’s say it is represented by a class with the following already implemented methods
Rows() – return of rows pyramid has
getValue(row, column) – returns a value that is at the given position e.g.getValue(1,2) is 7 in the example above
min(x,y)- return smaller number of x any

  1. Which number does the following method written in pseudocode return for the inverted pyramid from the example above? Note is calls a recursive method. Briefly describe how you got to the result

int evaluate (Pyramid pyramid)
{
return process(pyramid­.rows(), 1, pyramid);
}

Int process (Int row, int column, Pyramid pyramid)
{
If ( row == 1) return pyramid.getVa­lue(row, column);

Left = process(row – 1, column, pyramid);
Right = process(row – 1, column + 1,pyramid);

Result = pyramid.get Value(row, column) + min (left, right);

Return result;
}

  1. If you have time left finish the following code that that does the same only using for-loops

Int evaluate(Pyramid pyramid)
{
For ( int row = …
For (int column = …

Return result;
}

 
Odpovědět
9.4.2015 18:18
Avatar
coells
Tvůrce
Avatar
Odpovídá na alexneti
coells:9.4.2015 18:29

Víme, dá se to spočítat z hlavy. Proč ti nestačí odpovědi na stack-overflow? :-D http://stackoverflow.com/…at-is-return

 
Nahoru Odpovědět
9.4.2015 18:29
Avatar
alexneti
Člen
Avatar
alexneti:9.4.2015 18:47

Sakra asi jsem s tím možná až moc nápadný :D
Jakým způsobem se to spočítá z hlavy?

 
Nahoru Odpovědět
9.4.2015 18:47
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 3 zpráv z 3.