Water collected between towers: Difference between revisions
m
→{{header|Visual Basic .NET}}: Converted version 1 to .NET core, added "Module" constructs around both versions
m (→{{header|Visual Basic .NET}}: Converted version 1 to .NET core, added "Module" constructs around both versions) |
|||
Line 2,074:
=={{header|Visual Basic .NET}}==
===Version 1===
'''Method:''' Instead of "scanning" adjoining towers for each column,
The program can optionally display the interim string representation of each tower block before the final count is completed. I've since modified it to have the same block and wavy characters are the
[[{{FULLPAGENAME}}#version_3|REXX 9.3]] output, but used the double-wide columns, as pictured in the task definition area.
<lang vbnet>' Convert tower block data into a string representation, then manipulate that.
Module Module1
Sub Main(Args() As String)
Dim shoTow As Boolean = Environment.GetCommandLineArgs().Count > 1 ' Show towers.
Dim wta As Integer()() = { ' water tower array (input data).▼
New Integer() {
New Integer() {
New Integer() {
New Integer() {8, 7, 7, 6}, New Integer() {6, 7, 10, 7, 6}}
Dim blk As String, ' String representation of a block of towers.▼
▲
Dim bpf As Integer ' Count of tower blocks found per floor.
blk = ""
For j As Integer
Next
▲
While blk.Contains(" ≈≈") : blk = Replace(blk, " ≈≈", " ") : End While▼
While blk.Contains(
'
If shoTow Then Console.Write("{0}{1}", lf,
Console.Write("Block {0} retains {1,2} water units.{2}", i + 1,
Next
End Sub
End Module</lang>
{{out}}<lang>Block 1 retains 2 water units.
Block 2 retains 14 water units.
Line 2,193 ⟶ 2,194:
'''Method:''' More conventional "scanning" method. A Char array is used, but no Replace() statements. Output is similar to version 1, although there is now a left margin of three spaces, the results statement is immediately to the right of the string representation of the tower blocks (instead of underneath), the verb is "hold(s)" instead of "retains", and there is a special string when the results indicate zero.
<lang vbnet>Module
''' <summary>
''' wide - Widens the aspect ratio of a linefeed separated string.
''' </summary>
Line 2,289 ⟶ 2,291:
Console.WriteLine(report(block, blkCntr, verb, shoTow))
Next
End Sub
End Module</lang>
Regular version 2 output:
<lang> Block 1 holds 2 water units.
|