Last active
January 1, 2016 01:39
-
-
Save mertyildiran/8073834 to your computer and use it in GitHub Desktop.
QuickFind programı
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# QuickFind programı | |
# Mehmet Mert Yildiran 12060367 | |
# Ubuntu üzerinde çalıştırmak için: | |
# ruby quickfind.rb | |
class QuickFind | |
def initialize(n) | |
@ids = [] | |
0.upto(n-1) {|i| @ids[i] = i} | |
end | |
def connected?(id1,id2) | |
@ids[id1] == @ids[id2] | |
end | |
def union(id1,id2) | |
id_1, id_2 = @ids[id1], @ids[id2] | |
@ids.map! {|i| (i == id_1) ? id_2 : i } | |
end | |
end | |
class String | |
def numeric? | |
Float(self) != nil rescue false | |
end | |
end | |
puts "Hos geldiniz." | |
puts "\tSehirler tablosu:" | |
puts "\tAnkara\t\t1" | |
puts "\tIstanbul\t2" | |
puts "\tIzmir\t\t3" | |
puts "\tSamsun\t\t4" | |
puts "\tSinop\t\t5" | |
puts "\tBursa\t\t6" | |
puts "\tKonya\t\t7" | |
puts "\tKocaeli\t\t8" | |
puts "\tAntalya\t\t9" | |
puts "\tAdana\t\t10" | |
puts "Bagli sehirlerin numaralarini ikili kombinasyon olacak sekilde teker teker giriniz. Orn: '1' sonra '3' (Bitirmek icin 'end' giriniz.)" | |
qf = QuickFind.new 10 | |
while true do | |
input = gets.chomp | |
#İlk kontrol başlangıç | |
if input == "end" | |
puts "Veri giris islemi tamamlandi." | |
break | |
elsif input.numeric? and input.to_i < 11 | |
input2 = gets.chomp | |
#İkinci kontrol başlangıç | |
if input2 == "end" | |
puts "Veri giris islemi tamamlandi." | |
break | |
elsif input2.numeric? and input2.to_i < 11 | |
qf.union(input.to_i,input2.to_i) | |
puts "Tamamdir #{input.to_i} ve #{input2.to_i} numarali sehirler birbirine bagli." | |
puts "Yeni veriyi giriniz:" | |
else | |
puts "Yanlis formatta veya 10'dan buyuk bir sayi girdiniz." | |
puts "Veriyi tekrar giriniz:" | |
redo | |
end | |
#İkinci kontrol bitiş | |
else | |
puts "Yanlis formatta veya 10'dan buyuk bir sayi girdiniz." | |
puts "Veriyi tekrar giriniz:" | |
redo | |
end | |
#İlk kontrol bitiş | |
end | |
puts "Simdi iki sehirin birbirine bagli olup olmadigini kontrol etmek icin az onceki yontemle sehirlerin numaralarini giriniz:" | |
while true do | |
input = gets.chomp | |
#İlk kontrol başlangıç | |
if input == "end" | |
puts "Sorgu tamamlandi. Tesekkur ederiz." | |
break | |
elsif input.numeric? and input.to_i < 11 | |
input2 = gets.chomp | |
#İkinci kontrol başlangıç | |
if input2 == "end" | |
puts "Sorgu tamamlandi. Tesekkur ederiz." | |
break | |
elsif input2.numeric? and input2.to_i < 11 | |
if qf.connected?(input.to_i,input2.to_i) | |
puts "#{input.to_i} ve #{input2.to_i} numarali sehirler birbirine baglidir." | |
else | |
puts "#{input.to_i} ve #{input2.to_i} numarali sehirler birbirine bagli degildir!" | |
end | |
puts "Yeni sorgu giriniz:" | |
else | |
puts "Yanlis formatta veya 10'dan buyuk bir sayi girdiniz." | |
puts "Sorguyu tekrar giriniz:" | |
redo | |
end | |
#İkinci kontrol bitiş | |
else | |
puts "Yanlis formatta veya 10'dan buyuk bir sayi girdiniz." | |
puts "Sorguyu tekrar giriniz:" | |
redo | |
end | |
#İlk kontrol bitiş | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment