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..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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;
}
}
}

Düşüncesiz Adam

sizleri düşünmeyip buraya hiçbir şey yazmadım !

You may also like...

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

ERROR: si-captcha.php plugin: GD image support not detected in PHP!

Contact your web host and ask them to enable GD image support for PHP.

ERROR: si-captcha.php plugin: imagepng function not detected in PHP!

Contact your web host and ask them to enable imagepng for PHP.

Bu site, istenmeyenleri azaltmak için Akismet kullanıyor. Yorum verilerinizin nasıl işlendiği hakkında daha fazla bilgi edinin.