Другие языки программирования и технологии

Помогите с построением матрицы Виженера на C#

Что не так
string b = ("abcdefghijklmnopqrstu");
int len = b.Length;
int[] q = new int[len];
char[,] a = new char[len, len];

for (int i = 0; i < len; i++)
{

for (int j = 0; j < len; j++)
{
if ((i + j) < (len + 2))
{
if (j == 0)
{ j = 1; }

a[i, j] = b[j - 1];

}
else
{
a[i, j] = b[i + j - (len + 2)];
}
}
}

static void Main(string[] args)
{
string ish = "abcdefghijklmnopqrstuvwxyz";
int len = ish.Length;
int i;
for (i = 0; i < len; i++)
{
Console.WriteLine(str(ish, i, len));
}
Console.Read();

}

public static string str(string ish, int k, int len)
{
string ret = "";
string prom = "";
for(int i = 0; i < k; i++)
{
prom += ish[i];
}
ret += ish.Remove(0, k);
ret += prom;
return (ret);
}
Иван Шульжик
Иван Шульжик
536
Лучший ответ
Иван Шульжик А чтобы было красиво, то вот так:

static void Main(string[] args)
{
string ish = "abcdefghijklmnopqrstuvwxyz";
int len = ish.Length;
int i;
for (i = 0; i < len; i++)
{
Console.WriteLine(str(ish, i, len));
}
Console.Read();

}

public static string str(string ish, int k, int len)
{
string ret = "";
string prom = "";
for(int i = 0; i < k; i++)
{
prom += ish[i];
}
ret += ish.Remove(0, k);
ret += prom;
for (int i = 0; i < len*2; i += 2)
{
ret = ret.Insert(i, " ");
}
return (ret);
}
Сергей Посканьёв Спасибо Денис, я примерно понял твой код, но не до конца, мой уровень это начальный pascal,я понял так что это одномерный массив выстроенный в матрицу?
Если можешь, объясни что делает .Remove и .Insert, а еще логически в моем коде что неверно? Вот этот кусок?:
if ((i + j) < (len + 2))
{
if (j == 0)
{ j = 1; }

a[i, j] = b[j - 1];

}
Скрин некликабельный. Сделайте скрин только самой матрицы
ДM
Дмитрий M
3 269
static void Main(string[] args)
{
string b = ("abcdefghijklmnopqrstu");
int len = b.Length;
int q=0;
char[,] a = new char[len, len];

for (int i = 0; i < len; i++)
{

for (int j = 0; j < len; j++)
{
if (i == j)
{
if ((i + j) > len)
{
a[i, j] = b[q];
q = q + 2;
}
else
{
a[i, j] = b[i + j];
}
}
else
{
if (len > (i + j))
{
a[i, j] = b[j + i];
}
else
{
a[i, j] = b[i + j - len];
}
}

}

}
for (int i = 0; i < len; i++)
{

for (int j = 0; j < len; j++)
{
Console.Write(a[j, i] + " ");
}
Console.WriteLine();
}
Console.ReadKey();

Вот Двумерный если нужен...
Макс Пылаев if ((i + j) >= len)
{
a[i, j] = b[q];
q = q + 2;
}

в этих строчках >= нужно