Graflarda En Kısa Yolu Bulma

DrogbA

Forum Üyesi
Katılım
27 Ara 2020
Mesajlar
3,440
Tepkime puanı
0
Puanları
36
Bu Program C++ Builder 6 ile uyumludur.


oku.txt isimli klasöre aynı örnekte verildiği şekilde

Ör: istanbul,trabzon,10
ankara,samsun,5

gibi verilerinizi girdikten sonra oku.txt isimli dosyanın en başına gidip hangi iki şehir arasındaki en kısa
mesafeyi bulmak istiyorsanız şu formatta yazınız.

samsun,ankara,?

NOT: Yapı ağaç modunda olup gidiş modludur Örneğin : samsun,ankara,5 demek sadece samsundan ankaraya
sefer olduğunu göstermektedir. Program elbette ters modda düşünülüp geliştirebilir.


Kod:
 //---------------------------------------------------------------------------
 
#include <vcl.h>
#pragma hdrstop
 
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
 
void __fastcall TForm1::Button1Click(TObject *Sender)
{
bool donus=true;
String cek;
String cek2;
String virgul=",";
if(FileExists("oku.txt"))
{
ListBox1->Items->LoadFromFile("oku.txt");
 cek=ListBox1->Items->Strings[0];
 cek2=cek;
int tut=cek.Pos(virgul);
String baslangic=cek.Delete(tut,cek.Length());
cek2.Delete(1,tut);
tut=cek2.Pos(virgul);
cek2.Delete(tut,cek2.Length());
ListBox1->Items->Delete(0);
}
for(int i=0;i<ListBox1->Items->Count;i++)
{
String yakala=ListBox1->Items->Strings[i];
int position=yakala.Pos(virgul);
yakala.Delete(position,yakala.Length());
if(yakala==cek)
{
String atilacak=ListBox1->Items->Strings[i];
atilacak.Delete(1,position);
position=atilacak.Pos(virgul);
String boyut=atilacak;
atilacak.Delete(position,atilacak.Length());
boyut.Delete(1,position);
ListBox2->Items->Add(atilacak);
String olustur=cek+","+atilacak;
ListBox3->Items->Add(olustur);
}
}
ListBox2->Items->Clear();
int saydir=1;
while(donus==true)
{
String il;
 
for(int i=0;i<ListBox3->Items->Count;i++)
{
String aman;
for(int p=0;p<saydir;p++)
{
int pozisyon=ListBox3->Items->Strings[i].Pos(virgul);
il=ListBox3->Items->Strings[i];
il.Delete(1,pozisyon);
}
for(int p=0;p<ListBox1->Items->Count;p++)
{
String orada=ListBox1->Items->Strings[p];
int position=orada.Pos(virgul);
orada.Delete(position,orada.Length());
if(orada==il)
{
aman=ListBox1->Items->Strings[p];
int position=aman.Pos(virgul);
aman.Delete(1,position);
position=aman.Pos(virgul);
aman.Delete(position,aman.Length());
String olustur=ListBox3->Items->Strings[i]+","+aman;
ListBox2->Items->Add(olustur);
}
}
}
 
for(int sar=0;sar<ListBox3->Items->Count;sar++)
{
int varmi=ListBox3->Items->Strings[sar].Pos(cek2);
if(varmi!=0)
{
ListBox4->Items->Add(ListBox3->Items->Strings[sar]);
ListBox3->Items->Delete(sar);
}
}
ListBox3->Items->Clear();
for(int den=0;den<ListBox2->Items->Count;den++)
{
ListBox3->Items->Add(ListBox2->Items->Strings[den]);
}
saydir++;
 
ListBox2->Items->Clear();
for(int of=0;of<ListBox3->Items->Count;of++)
{   //1
String cekbre=ListBox3->Items->Strings[of];
for(int oy=0;oy<saydir;oy++)
{
int position=cekbre.Pos(virgul);
cekbre.Delete(1,position);
}
for(int pes=0;pes<ListBox1->Items->Count;pes++)
{
 String yeter=ListBox1->Items->Strings[pes];
 int virgulinyeri=yeter.Pos(virgul);
 yeter.Delete(virgulinyeri,yeter.Length());
 if(yeter==cekbre)
 {
  String usak=ListBox1->Items->Strings[pes];
  virgulinyeri=usak.Pos(virgul);
  usak.Delete(1,virgulinyeri);
  virgulinyeri=usak.Pos(virgul);
  usak.Delete(virgulinyeri,usak.Length());
  int denetim=(ListBox3->Items->Strings[of]).Pos(usak);
  if(denetim==0)
  {
  String olustur=ListBox3->Items->Strings[of];
  olustur+=","+usak;
  ListBox2->Items->Add(olustur);
  }
 }
}
}  //1
 
if(ListBox2->Items->Count==0)
donus=false;
}  //while
 
for(int p=0;p<ListBox4->Items->Count;p++)
{
String kopya1=ListBox4->Items->Strings[p];
int virgulbe=kopya1.Pos(virgul);
int sayi=0;
String nedir;
while(virgulbe!=0)
{
String kopya2=kopya1;
kopya1.Delete(virgulbe,kopya1.Length());
kopya2.Delete(1,virgulbe);
String ikinci=kopya2;
virgulbe=ikinci.Pos(virgul);
ikinci.Delete(virgulbe,ikinci.Length());
String olustur=kopya1+","+ikinci;
 
for(int oeh=0;oeh<ListBox1->Items->Count;oeh++)
{
 int olurmu=ListBox1->Items->Strings[oeh].Pos(olustur);
 if(olurmu!=0)
 {
 nedir=ListBox1->Items->Strings[oeh];
 int yeri=nedir.Pos(virgul);
 nedir.Delete(1,yeri);
 yeri=nedir.Pos(virgul);
 nedir.Delete(1,yeri);
 sayi+=StrToInt(nedir);
 }
}
kopya1=kopya2;
virgulbe=kopya2.Pos(virgul);
 
}
ListBox2->Items->Add(sayi);
}
ListBox3->Items->Clear();
int enkucuk=100000;
for(int a=0;a<ListBox2->Items->Count;a++)
{
 if(StrToInt(ListBox2->Items->Strings[a])<enkucuk)
 enkucuk=StrToInt(ListBox2->Items->Strings[a]);
}
 
for(int a=0;a<ListBox2->Items->Count;a++)
{
if(StrToInt(ListBox2->Items->Strings[a])==enkucuk)
ListBox3->Items->Add(ListBox4->Items->Strings[a]+"->"+enkucuk);
}
 ListBox3->Items->SaveToFile("sonuc.txt");
 ListBox2->Items->Clear();
 ListBox4->Items->Clear();        
}
//---------------------------------------------------------------------------
 

Nutella

Bayan Üye
Özel Üye
Katılım
2 Ocak 2021
Mesajlar
3,559
Tepkime puanı
0
Puanları
36
Cinsiyet
  1. Bayan
Takım
Galatasaray
Paylaşım için teşekkürler.
 
metal işleme
Üst