Notes
Notes - notes.io |
#include <string>
#include <vector>
using namespace std;
class Yol {
public:
string yolismi;
Yol(const char* a) {
yolismi = a;
}
Yol(string a) {
yolismi = a;
}
Yol() {
Fiyat = 0;
}
int Fiyat = 0;
};
class Sehir :public Yol {
public:
string isim;
vector<Yol*> sonraki_yol;
//Yol** sonraki_yol;
vector<Sehir*> sonraki_sehir;
//Sehir** sonraki_sehir;
Sehir() {
}
Sehir(const char * a) {
isim = a;
}
Sehir(char a) {
isim = a;
}
Sehir(string a) {
isim = a;
}
};
void hesapla(Sehir* sehir, int yolParasi) {
int tempYolParasi = yolParasi;
cout << sehir->isim << " deyim, " << yolParasi << " tl var" << endl;
//Gidilebilecek şehir kalmadıysa dön
if (sehir->sonraki_yol.size() == 0)
return;
//Paran Bittiyse Dön
if (yolParasi < sehir->sonraki_yol[0]->Fiyat) {
cout << "Param bitti" << endl;
return;
}
//İlk şehre git ve paran bitene kadar diğerlerine git
yolParasi -= sehir->sonraki_yol[0]->Fiyat;
hesapla(sehir->sonraki_sehir[0], yolParasi);
//Şehir dizisini sola kaydır
//sehir->sonraki_yol[0]->gitti = true;
if (sehir->sonraki_yol.size() != 0) {
sehir->sonraki_sehir.erase(sehir->sonraki_sehir.begin());
sehir->sonraki_yol.erase(sehir->sonraki_yol.begin());
}
if (sehir->sonraki_yol.size() != 0) {
hesapla(sehir, tempYolParasi);
}
}
int main() {
string sehirlistesi;
string yollistesi;
string yer_para;
char giris[100];
/*Sehir* A = new Sehir("A");
Sehir* B = new Sehir("B");
Sehir* C = new Sehir("C");
Sehir* D = new Sehir("D");
Yol* AC = new Yol("AC");
Yol* CB = new Yol("CB");
Yol* CD = new Yol("CD");
Yol* DB = new Yol("DB");
Yol* BA = new Yol("BA");
AC->Fiyat = 3;
CB->Fiyat = 4;
CD->Fiyat = 5;
DB->Fiyat = 6;
BA->Fiyat = 2;
A->sonraki_yol.push_back(AC);
B->sonraki_yol.push_back(BA);
C->sonraki_yol.push_back(CB);
C->sonraki_yol.push_back(CD);
D->sonraki_yol.push_back(DB);
A->sonraki_sehir.push_back(C);
B->sonraki_sehir.push_back(A);
C->sonraki_sehir.push_back(B);
C->sonraki_sehir.push_back(D);
D->sonraki_sehir.push_back(B);*/
cout << "Enter all the nodes in topo:";
cin >> sehirlistesi;
vector<Sehir*> sehirler;
for (int i = 0; i < sehirlistesi.length(); i++) {
char abc = sehirlistesi[i];
Sehir* temp = new Sehir(abc);
sehirler.push_back(temp);
}
cout << "Enter the links [FROM][DEST][COST] to finsh enter END";
while (yollistesi != "END") {
cin >> yollistesi;//AC3
if (yollistesi == "END")
break;
string yol_adi = yollistesi.substr(0, 2);//AC
string suanki_konum = yollistesi.substr(0,1);//A
string hedef = yollistesi.substr(1, 1);//C
string fiyat = yollistesi.substr(2,3);//3
Yol* temp = new Yol(yol_adi);
temp->Fiyat = stoi(fiyat);
for (int i = 0; i < sehirler.size(); i++) {
if (sehirler[i]->isim == suanki_konum){
sehirler[i]->sonraki_yol.push_back(temp);
for (int k = 0; sehirler.size(); k++) {
if (sehirler[k]->isim == hedef){
sehirler[i]->sonraki_sehir.push_back(sehirler[k]);
break;
}
}
break;
}
}
}
cout << endl << "Find all the posible routes for a given start point and budget. [FROM],[BUDGET] PLEASE USE COMMA"<<endl;
cin >> giris;
string baslangic;
string butce;
baslangic = giris[0];
butce = giris;
butce = butce.substr(2, butce.length());
int k = 0;
for (unsigned int i = 0; i < sehirler.size(); i++) {
if (sehirler[i]->isim == baslangic){
hesapla(sehirler[i], stoi(butce));
break;
}
}
system("pause");
return 0;
}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team