Skip to content

Commit c3d1117

Browse files
committed
Multidimensional Arrays
1 parent f11d5d1 commit c3d1117

File tree

21 files changed

+749
-0
lines changed

21 files changed

+749
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace _00.Lab.SumMatrixElements
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
int[] rowsAndColumns = Console.ReadLine()
14+
.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
15+
.Select(int.Parse)
16+
.ToArray();
17+
18+
int[,] matrix = new int[rowsAndColumns[0], rowsAndColumns[1]];
19+
20+
21+
22+
for (int rows = 0; rows < rowsAndColumns[0]; rows++)
23+
{
24+
25+
var rowvalues = Console.ReadLine()
26+
.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
27+
.Select(int.Parse)
28+
.ToArray();
29+
30+
for (int columns = 0; columns < rowsAndColumns[1]; columns++)
31+
{
32+
matrix[rows, columns] = rowvalues[columns];
33+
}
34+
}
35+
36+
int sum = 0;
37+
38+
for (int rows = 0; rows < matrix.GetLength(0); rows++)
39+
{
40+
for (int columns = 0; columns < matrix.GetLength(1); columns++)
41+
{
42+
sum += matrix[rows, columns];
43+
}
44+
}
45+
46+
Console.WriteLine(matrix.GetLength(0));
47+
Console.WriteLine(matrix.GetLength(1));
48+
Console.WriteLine(sum);
49+
50+
51+
52+
}
53+
}
54+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{7D715907-A74B-4B51-A95E-FF40BBBB6074}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>_00.Lab.SumMatrixElements</RootNamespace>
10+
<AssemblyName>00.Lab.SumMatrixElements</AssemblyName>
11+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Core" />
37+
<Reference Include="System.Xml.Linq" />
38+
<Reference Include="System.Data.DataSetExtensions" />
39+
<Reference Include="Microsoft.CSharp" />
40+
<Reference Include="System.Data" />
41+
<Reference Include="System.Net.Http" />
42+
<Reference Include="System.Xml" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Compile Include="00.Lab.SumMatrixElements.cs" />
46+
<Compile Include="Properties\AssemblyInfo.cs" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<None Include="App.config" />
50+
</ItemGroup>
51+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
52+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5+
</startup>
6+
</configuration>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("00.Lab.SumMatrixElements")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("00.Lab.SumMatrixElements")]
13+
[assembly: AssemblyCopyright("Copyright © 2018")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("7d715907-a74b-4b51-a95e-ff40bbbb6074")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace _00.Lab.SumMatrixElements
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
int[] rowsAndColumns = Console.ReadLine()
14+
.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
15+
.Select(int.Parse)
16+
.ToArray();
17+
18+
int[,] matrix = new int[rowsAndColumns[0], rowsAndColumns[1]];
19+
20+
21+
22+
for (int rows = 0; rows < rowsAndColumns[0]; rows++)
23+
{
24+
25+
var rowvalues = Console.ReadLine()
26+
.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
27+
.Select(int.Parse)
28+
.ToArray();
29+
30+
for (int columns = 0; columns < rowsAndColumns[1]; columns++)
31+
{
32+
matrix[rows, columns] = rowvalues[columns];
33+
}
34+
}
35+
36+
int sum = 0;
37+
int rowIndex = 0;
38+
int columnIndex = 0;
39+
40+
for (int rows = 0; rows < matrix.GetLength(0) - 1; rows++)
41+
{
42+
for (int columns = 0; columns < matrix.GetLength(1) - 1; columns++)
43+
{
44+
var tempSum = matrix[rows, columns] + matrix[rows, columns + 1] +
45+
matrix[rows + 1, columns] + matrix[rows + 1, columns + 1];
46+
47+
if (tempSum > sum)
48+
{
49+
sum = tempSum;
50+
rowIndex = rows;
51+
columnIndex = columns;
52+
}
53+
}
54+
}
55+
56+
Console.WriteLine(matrix[rowIndex, columnIndex] + " " + matrix[rowIndex, columnIndex + 1]);
57+
Console.WriteLine(matrix[rowIndex + 1, columnIndex] + " " + matrix[rowIndex + 1, columnIndex + 1]);
58+
Console.WriteLine(sum);
59+
60+
61+
62+
}
63+
}
64+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{BF416C97-337F-4661-816B-8A1AB8666E36}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>_001.Lab.SquareWithMaximumSum</RootNamespace>
10+
<AssemblyName>001.Lab.SquareWithMaximumSum</AssemblyName>
11+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Core" />
37+
<Reference Include="System.Xml.Linq" />
38+
<Reference Include="System.Data.DataSetExtensions" />
39+
<Reference Include="Microsoft.CSharp" />
40+
<Reference Include="System.Data" />
41+
<Reference Include="System.Net.Http" />
42+
<Reference Include="System.Xml" />
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Compile Include="001.Lab.SquareWithMaximumSum.cs" />
46+
<Compile Include="Properties\AssemblyInfo.cs" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<None Include="App.config" />
50+
</ItemGroup>
51+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
52+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5+
</startup>
6+
</configuration>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("001.Lab.SquareWithMaximumSum")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("001.Lab.SquareWithMaximumSum")]
13+
[assembly: AssemblyCopyright("Copyright © 2018")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("bf416c97-337f-4661-816b-8a1ab8666e36")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace _003.Lab.CreatingJaggedArray
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
int rows = int.Parse(Console.ReadLine());
14+
15+
int[][] jaggedArray = new int[rows][];
16+
17+
for (int rowsCounter = 0; rowsCounter < rows; rowsCounter++)
18+
{
19+
jaggedArray[rowsCounter] = Console.ReadLine().Split(',').Select(int.Parse).ToArray();
20+
}
21+
22+
23+
for (int rowsCounter = 0; rowsCounter < jaggedArray.Length; rowsCounter++)
24+
{
25+
var row = jaggedArray[rowsCounter];
26+
27+
for (int index = 0; index < row.Length; index++)
28+
{
29+
Console.Write(row[index]);
30+
//Console.WriteLine(jaggedArray[rowsCounter][index]);
31+
}
32+
Console.WriteLine();
33+
}
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)