If row i is an integer multiple of row j, then you have
to output
p#q where p is the minimum of (i,j) and q is the maximum of (i,j).
If there are multiple possibilities for i and j, you have to print for the
smallest i and the smallest j.
Otherwise, you have to output
0#0
please,I recommend to solve in C language compiler because compiler gives so many errors
What I have tried:
this program has so many errors
#include<stdio.h>
static int M = 4;
static int N = 5;
static int preProcess(int [,]mat, int [,]aux)
{
for (int i = 0; i < N; i++)
aux[0,i] = mat[0,i];
for (int i = 1; i < M; i++)
for (int j = 0; j < N; j++)
aux[i,j] = mat[i,j] + aux[i-1,j];
for (int i = 0; i < M; i++)
for (int j = 1; j < N; j++)
aux[i,j] += aux[i,j-1];
return 0;
}
static int sumQuery(int [,]aux, int tli,
int tlj, int rbi, int rbj)
{
int res = aux[rbi,rbj];
if (tli > 0)
res = res - aux[tli-1,rbj];
if (tlj > 0)
res = res - aux[rbi,tlj-1];
if (tli > 0 && tlj > 0)
res = res + aux[tli-1,tlj-1];
return res;
}
public static void Main ()
{
int [,]mat = {{1, 2, 3, 4, 6},
{5, 3, 8, 1, 2},
{4, 6, 7, 5, 5},
{2, 4, 8, 9, 4}};
int [,]aux = new int[M,N];
preProcess(mat, aux);
int tli = 2, tlj = 2, rbi = 3, rbj = 4;
Console.Write("\nQuery1: " +
sumQuery(aux, tli, tlj, rbi, rbj));
tli = 0; tlj = 0; rbi = 1; rbj = 1;
Console.Write("\nQuery2: " +
sumQuery(aux, tli, tlj, rbi, rbj));
tli = 1; tlj = 2; rbi = 3; rbj = 3;
Console.Write("\nQuery3: " +
sumQuery(aux, tli, tlj, rbi, rbj));
}
}