Конвертировать с Pascal на C# - C# (182859)
Формулировка задачи:
Собственно сам код:
Заранее спасибо)
const DMAX=100;
var
N: integer;
D: integer;
K: integer;
r: integer;
c: array[1..DMAX-1] of integer;
i: integer;
imax: integer;
begin
for i:=1 to DMAX-1 do c[i]:=0;
readln(N);
for i:=1 to N do begin
readln(D, K);
r := K mod D;
if r>0 then c[r]:=c[r]+1;
end;
imax:=1;
for i:=2 to DMAX-1 do begin
if c[i]>=c[imax] then imax:=i;
end;
if c[imax]=0 then imax:=0;
writeln(imax);
end.Решение задачи: «Конвертировать с Pascal на C#»
textual
Листинг программы
using System;
class Convert
{
const int DMAX = 100;
static void Main()
{
int N, D, K, r, i, imax;
int[] c = new int[DMAX-1];
string[] s;
for ( i = 0; i < DMAX - 1; i++) c[i] = 0;
N = Int32.Parse(Console.ReadLine());
for (i = 0; i < N; i++)
{
s = Console.ReadLine().Split(null);
D = Int32.Parse(s[0]);
K = Int32.Parse(s[1]);
r = K / D;
if (r > 0) c[r] = c[r] + 1;
}
imax = 1;
for (i = 2; i < DMAX - 1; i++) if (c[i] >= c[imax]) imax = i;
if (c[imax] == 0) imax = 0;
Console.WriteLine(imax);
}
}