C# – Mısır Piramitleri – Algoritma
C# ile Console Application üzerinde Mısır Piramitleri çizdirdik. Yükseklikleri,piramit sayılarını,aralarındaki mesafeleri ve arkaplan text’ini klavyeden aldırıyoruz ve Piramitler ekrana çizdiriliyor. İyi bir algoritma sorusudur. Aklınızda bulunsun..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Piramit
{
class Program
{
static int padet;
static int[] yukseklikler;
//static int[] genislikler;
static int[] mesafeler;
static string arkatxt;
static string[,] area = new string[22, 80];
static void Main(string[] args)
{
Console.WriteLine("Kaç Piramit Goruntulenecek?:");
padet = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Yukseklikler Nedir?:");
yukseklikler = Ayir(Console.ReadLine(), padet);
Console.WriteLine("Mesafeler Nedir?:");
mesafeler = Ayir(Console.ReadLine(), padet - 1);
Console.WriteLine("Arkaplan Olarak Ne Kullanılacak?:");
arkatxt = Console.ReadLine();
//genislikler = GenislikBul();
Islem();
Bosalt();
Console.ReadKey();
}
private static void Bosalt()
{
for (int i = 0; i < 21; i++)
for (int j = 0; j < 80; j++)
{
Console.Write(area[i,j]);
}Console.WriteLine();
}
static int[] StartsBul()
{
int[] temp=new int[mesafeler.Length];
for (int i = 0; i < mesafeler.Length; i++)
{
if (i == 0)
{
temp[i] = mesafeler[i] + yukseklikler[i] + 1;
}
else
{
for (int j = i; j >= 0; j--)
{
temp[i] += mesafeler[j];
}
temp[i] += yukseklikler[i] + 1;
}
}
return temp;
}
//static int[] GenislikBul()
//{
// int[] temp =new int[yukseklikler.Length];
// for (int i = 0; i < yukseklikler.Length; i++)
// {
// temp[i] = (yukseklikler[i]*2) + 2;
// }
// return temp;
//}
static void Doldur()
{
int index = 0;
for (int h = 0; h < 22; h++)
{
for (int g = 0; g < 80; g++)
{
if (index < (arkatxt.Length - 1))
{
area[h, g] = arkatxt[index].ToString();
index++;
}
else
{
area[h, g] = arkatxt[index].ToString();
index = 0;
}
}
}
}
static void Islem()
{
Doldur();
int[] starts = StartsBul();
for (int c=(padet-1); c >= 0; c--)
{
int ickisim = 0;
for (int a = 21; a > 0; a--)
{
for (int b = 0; b < 80; b++)
{
if (a <= yukseklikler[c])
{
if (starts[c] == b)
{
area[21 - a, b] = "/";
if (ickisim != 0)
for (int d = 0; d < ickisim; d++)
{
b++;
area[21 - a, b] = "-";
}
ickisim += 2;
b++;
area[21 - a, b] = "\\";
starts[c]--;
}
}
}
}
}
}
static int[] Ayir(string st, int adet)
{
String [] arr= st.Split(' ');
int[] array=new int[padet];
int i = 0;
if (adet < padet)
{
array[0] = 0;
i = 1;
}
foreach (var s in arr)
{
array[i] = Convert.ToInt32(s);
i++;
}
return array;
}
}
}

