read edges from stdin instead of argv

This commit is contained in:
josch 2013-04-11 09:59:01 +02:00
parent dfb8541218
commit 11d7e62232
2 changed files with 16 additions and 12 deletions

View file

@ -137,8 +137,8 @@ let find_all_cycles_johnson g =
List.rev result List.rev result
;; ;;
if Array.length Sys.argv < 3 then begin if Array.length Sys.argv != 2 then begin
Printf.printf "usage: %s num_vertices [v1,v2...]\n" Sys.argv.(0); Printf.printf "usage: echo \"v1 v2\nv1 v3\n...\" | %s num_vertices\n" Sys.argv.(0);
exit 1; exit 1;
end; end;
@ -147,10 +147,12 @@ let g = G.create ~size:v () in
let a = Array.init v G.V.create in let a = Array.init v G.V.create in
for i = 2 to Array.length Sys.argv - 1 do try
let v1, v2 = String.split Sys.argv.(i) "," in while true do
G.add_edge g a.(int_of_string v1) a.(int_of_string v2); let v1, v2 = String.split (read_line ()) " " in
done; G.add_edge g a.(int_of_string v1) a.(int_of_string v2);
done;
with End_of_file -> ();
let ll = find_all_cycles_johnson g in let ll = find_all_cycles_johnson g in
List.iter (fun path -> List.iter (fun path ->

View file

@ -130,8 +130,8 @@ let find_all_cycles_johnson g =
List.rev !result List.rev !result
;; ;;
if Array.length Sys.argv < 3 then begin if Array.length Sys.argv != 2 then begin
Printf.printf "usage: %s num_vertices [v1,v2...]\n" Sys.argv.(0); Printf.printf "usage: echo \"v1 v2\nv1 v3\n...\" | %s num_vertices\n" Sys.argv.(0);
exit 1; exit 1;
end; end;
@ -140,10 +140,12 @@ let g = G.create ~size:v () in
let a = Array.init v G.V.create in let a = Array.init v G.V.create in
for i = 2 to Array.length Sys.argv - 1 do try
let v1, v2 = String.split Sys.argv.(i) "," in while true do
G.add_edge g a.(int_of_string v1) a.(int_of_string v2); let v1, v2 = String.split (read_line ()) " " in
done; G.add_edge g a.(int_of_string v1) a.(int_of_string v2);
done;
with End_of_file -> ();
let ll = find_all_cycles_johnson g in let ll = find_all_cycles_johnson g in
List.iter (fun path -> List.iter (fun path ->