Salut à tous,
Je me présente, je suis un étudiant qui réside au Portugal, je débute tout juste dans ce langage, je dois réaliser un programme qui puisse faire la multiplication de deux polynômes avec un maximum de 3 variables, comme l’exemple suivant :
Sur la première ligne : 2.x^2.y.z + 3.x.y.z + 4
Sur la deuxième ligne : 2.x^2.y.z + 3.x.y.z + 4
Le résultat : 4.x^4.y^2.z^2 + 12.x^3.y^2.z^2 + 9.x^2.y^2.z^2 + 16.x^2.y.z + 24.x.y.z + 16
Pour l’instant, je n’ai que ça :
Je vous remercie sincèrement de votre aide, Snyper_ubi
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
49
50 (*Problema B Autor: Luis-Filipe Marcos Parente a15196 Eng. Informatica*) open List;; open Printf;; open Str;; type componente = int*((string*int) list);; type polinomio = componente list;; (*type componente defined;;*) (*type polinomio defined;;*) let poly1 = read_line();; let poly2 = read_line();; let separar_mais l = let reg_mais = regexp_string " + " in split reg_mais l;; let separar_ponto l = let reg_ponto = regexp_string "." in split reg_ponto l;; let separar_pot l = let reg_pot = regexp_string "^" in split reg_pot l;; let ler_polinomio s = List.map (fun x -> (List.map separar_pot x)) (List.map separar_ponto (separar_mais s));; let p = ler_polinomio poly1;; let rec tamanho l = match l with [] -> 0 |_::li -> 1 + tamanho li;; let m = tamanho p;; (*let print_list = fun p -> (do_list print_string p ; print_newline());;*) (*List.iter f p;;*) (*Printf.printf "%d\n" m;;*) (*List.iter print_string p;;*)
Partager