C
C#7d ago
Archion

Variable is 0

Me doing matrix stuff and the minimum is 0 somehow.
8 Replies
Archion
ArchionOP7d ago
input:
3 3
1 2 3
4 5 6
7 8 9
3 3
1 2 3
4 5 6
7 8 9
le code:
string[] nm = Console.ReadLine().Split(' ');
int n = Convert.ToInt32(nm[0]);
int m = Convert.ToInt32(nm[1]);

int[][] h = new int[n][];

for (int i = 0; i < n; i++){
string[] line = Console.ReadLine().Split(' ');
for (int j = 0;j<line.Length;j++){
h[i] = new int[m];
h[i][j] = Convert.ToInt32(line[j]);
}

}
Console.WriteLine();
int sor=0;
int max=h[0][0];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if(max < h[i][j]){
sor=i;
max=h[i][j];
}
}
}

int min = h[sor][0];

for (int i = 0; i < m; i++)
{
if(h[sor][i]<min){
min = h[sor][i];
}
}
Console.WriteLine("{0}", min);

int db = 0;
List<int> k = new List<int>();
for (int i = 0; i < m; i++)
{
if(h[sor][i] == min){
db++;
k.Add(i);
}
}
//k=k.Select(x => x+1).ToList();
Console.WriteLine("{0} {1}",db,string.Join(" ",k));
string[] nm = Console.ReadLine().Split(' ');
int n = Convert.ToInt32(nm[0]);
int m = Convert.ToInt32(nm[1]);

int[][] h = new int[n][];

for (int i = 0; i < n; i++){
string[] line = Console.ReadLine().Split(' ');
for (int j = 0;j<line.Length;j++){
h[i] = new int[m];
h[i][j] = Convert.ToInt32(line[j]);
}

}
Console.WriteLine();
int sor=0;
int max=h[0][0];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if(max < h[i][j]){
sor=i;
max=h[i][j];
}
}
}

int min = h[sor][0];

for (int i = 0; i < m; i++)
{
if(h[sor][i]<min){
min = h[sor][i];
}
}
Console.WriteLine("{0}", min);

int db = 0;
List<int> k = new List<int>();
for (int i = 0; i < m; i++)
{
if(h[sor][i] == min){
db++;
k.Add(i);
}
}
//k=k.Select(x => x+1).ToList();
Console.WriteLine("{0} {1}",db,string.Join(" ",k));
cathei
cathei7d ago
You are making new array for every j loop :catthinking:
Izsák
Izsák7d ago
hey cathei can u help me too?
ero
ero7d ago
Create your own thread...?
Archion
ArchionOP7d ago
oh mai god i made my worst mistake
Izsák
Izsák7d ago
i already did
ero
ero7d ago
Then be patient
Izsák
Izsák7d ago
ok
Want results from more Discord servers?
Add your server