language: Ocaml (ocamlopt 3.10.2)
date: 144 days 10 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
open Array;;
open String;;
open Printf;;
 
let n1 = read_int();;
let seq1 = read_line();;
let n2 = read_int();;
let seq2 = read_line();;
let matriz = Array.make_matrix (n1+2) (n2+2) 0;;
let s1=String.copy seq1;;
let s2=String.copy seq2;;
 
let detvalor i j s1 s2 matriz=
  if i = 0 || j = 0 then 0 else if (s1.[i-1] = s2.[j-1]) then (1 + matriz.(i-1).(j-1)) else 0;;
 
for i=0 to n2 do 
  for j=0 to n1 do
    matriz.(i).(j) <- (detvalor i j s1 s2 matriz)
  done;
done;;
 
let maximo = ref 0;;
let pos1 = ref 0;;
let pos2 = ref 0;;
 
for i=0 to n2 do
for j=0 to n1 do
if !maximo < matriz.(i).(j) then
  begin
    maximo:=matriz.(i).(j);
    pos1:=i;
    pos2:=j
  end
done;
done;;
 
let rec detposinicial pos1 pos2 =
  if matriz.(pos1).(pos2) = 1 then (pos1, pos2)
  else (detposinicial (pos1-1) (pos2-1));;
 
let inicio = (detposinicial !pos1 !pos2);;
let primeiro (x, _) = x;;
let segundo (_, x) = x;;
 
let rec juntarcaracteres s1 pos1i pos2i pos1 pos2 =
  (String.make 1 s1.[pos1i-1]) ^ (juntarcaracteres s1 (pos1i+1) (pos2i+1) (pos1) (pos2));;
 
printf ("%s\n") (juntarcaracteres s1 (primeiro inicio) (segundo inicio) pos1 pos2);;
  • upload with new input
  • result: Runtime error     time: 0.01s    memory: 2780 kB     signal: -1

    open Array;;
    open String;;
    open Printf;;
    
    let n1 = 61;;
    let seq1 = "AACGTTGAGATTGAAGTCCGTGCATGGCCCGTGAGAGTCACTTTCGGATTAGCTGTGAATG";;
    let n2 = 45;;
    let seq2 = "AACATTGCGTAATGGCCGTAGGCCCGTGAGAGTCACTTTCTTGAT";;
    let matriz = Array.make_matrix (n1+1) (n2+1) 0;;
    let s1=String.copy seq1;;
    let s2=String.copy seq2;;
    
    let detvalor i j s1 s2 matriz=
      if i = 0 || j = 0 then 0 else if (s1.[i-1] = s2.[j-1]) then (1 + matriz.(i-1).(j-1)) else 0;;
    
    for i=0 to n2 do 
      for j=0 to n1 do
        matriz.(i).(j) <- (detvalor i j s1 s2 matriz)
      done;
    done;;
    
    let maximo = ref 0;;
    let pos1 = ref 0;;
    let pos2 = ref 0;;
    
    for i=0 to n2 do
    for j=0 to n1 do
    if !maximo < matriz.(i).(j) then
      begin
        maximo:=matriz.(i).(j);
        pos1:=i;
        pos2:=j
      end
    done;
    done;;
    
    let rec detposinicial pos1 pos2 =
      if matriz.(pos1).(pos2) = 1 then (pos1, pos2)
      else (detposinicial (pos1-1) (pos2-1));;
    
    let inicio = (detposinicial !pos1 !pos2);;
    let primeiro (x, _) = x;;
    let segundo (_, x) = x;;
    
    let rec juntarcaracteres s1 pos1i pos2i pos1 pos2 =
      (String.make 1 s1.[pos1i-1]) ^ (juntarcaracteres s1 (pos1i+1) (pos2i+1) (pos1) (pos2));;
    
    printf ("%s\n") (juntarcaracteres s1 (primeiro inicio) (segundo inicio) pos1 pos2);;
    Fatal error: exception Failure("int_of_string")