static void Main(string[] args)
{
string aranacak = "Buralar Eskiden Hep Otlakmis";
string aranan = "Ot";
int sayi = StringSearch(aranacak, aranan);
Console.WriteLine(sayi.ToString());
Console.ReadKey();
}
static int StringSearch(string aranacak, string aranan)
{
int toplam = 0;
int a = 0;
aranan = aranan.ToLower();
aranacak = aranacak.ToLower();
for (int i = 0; i < aranacak.Length; i++)
{
if (aranacak[i] == aranan[a])
{
if (a == aranan.Length - 1)
{
a = 0;
toplam += 1;
}
else
a++;
}
else
a = 0;
}
return toplam;
}
27 Eylül 2013 Cuma
StringSearch
Bir string içindeki bir kelimenin kaç kere bulunduğunu döndürür.
Stringdeki katsayıları ayırıp çarpmak
bir stringdeki bütün sayıları birbiriyle çarpan basit bir algoritma :)
Aldığım sonuçlar :
1) 87e5x34t = 87 * 5 * 34 =14790
2) 74582ex0e5 = 74582*0*5 = 0
3)74582ex05e5 = 1864550 (05 in yazımı hatalı)
4)12ex420k5i7 = 72*420*5*7 = 176400
1) 87e5x34t = 87 * 5 * 34 =14790
2) 74582ex0e5 = 74582*0*5 = 0
3)74582ex05e5 = 1864550 (05 in yazımı hatalı)
4)12ex420k5i7 = 72*420*5*7 = 176400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace paralel1
{
class Program
{
static void Main(string[] args)
{
string asd = "87e5x34t";
List list = new List();
Console.WriteLine("Sonuc : {0}", StringKatsayi(asd,list));
for (int i = 0; i < list.Count; i++)
{
Console.WriteLine(String.Format("{0} .ci deger : {1}", i + 1, list[i]));
}
Console.ReadKey();
}
static int StringKatsayi(string yazi,List liste)
{
int anatoplam = 1;
int toplam = 0;
int katsayi = 1;
int tmp = 1;
char cr;
bool gordumu = false;
for (int i = yazi.Length - 1; i >= 0; i--)
{
cr = yazi[i];
if (cr > 47 && cr < 58)
{
tmp = cr - 48;
toplam += katsayi * tmp;
katsayi *= 10;
gordumu = true;
}
else
{
if (gordumu == true)
{
liste.Add(toplam);
katsayi = 1;
toplam = 0;
gordumu = false;
}
}
}
if (gordumu == true)
liste.Add(toplam);
for (int i = 0; i < liste.Count; i++)
{
anatoplam *= liste[i];
}
return anatoplam;
}
}
}
18 Eylül 2013 Çarşamba
c#ta infix notasyonu prefixe çevirmek
Prefix ve postfix hesap makinalarında,derleyicilerde kullanılan 4 işlem tekniklerinden birisidir .Bizim bildiğimiz matematiksel denklemleri, fonksiyonları parantez kullanmadan yazmamızı sağlayan bir tekniktir. Polish notation olarak da geçer .Alttaki linkler genel fikri verecektir
http://itviewson.files.wordpress.com/2012/06/infixprefixpostfix.pdf
http://www.cs.man.ac.uk/~pjj/cs2121/fix.html
http://www.cs.man.ac.uk/~pjj/cs2121/fix.html
class Notations
{
string fnk;
char[] oparray = { '+', '-', '/', '*', '^' };
public Notations(string infix)
{
this.fnk = infix;
}
bool operandmi(char cr)
{
int i = 0;
while (i<5)
{
if (cr == oparray[i])
return true;
}
return false;
}
public string prefix()
{
string asd = fnk;
Stack OpStack = new Stack();
Stack PrefixStack = new Stack();
int i = asd.Length-1;
while (i>=0)
{
char cr = asd[i];
if (cr > 47 && cr < 58)
{
PrefixStack.Push(cr);
PrefixStack.Push(',');
i--;
}
else
{
int j = 0;
while ( j<5 && cr!=oparray[j] )
{
j++;
}
if (j != 5)
{
OpStack.Push(cr);
i--;
}
else
{
if (cr == ')')
{
OpStack.Push(')');
i--;
}
else
{
if (cr == '(')
{
char cr2;
do
{
cr2=OpStack.Pop();
if (cr2 != ')')
PrefixStack.Push(cr2);
} while (cr2==')');
OpStack.Pop();
i--;
}
}
}
}
}
while (OpStack.Count!=0)
{
PrefixStack.Push(OpStack.Pop());
}
StringBuilder bl = new StringBuilder();
while (PrefixStack.Count!=0)
{
bl.Append(PrefixStack.Pop());
}
return bl.ToString();
}
}
Kaydol:
Yorumlar (Atom)