Informatique

Question

soit ch une variable donnée de type chaine de caractère. on vous demande de supprimer la sous_ chaine comprise entre parenthèses de la chaine de caractères ch. les parentheses doivent etre aussi supprimées.
Exemples: Pour ch="3 ème (ann"e) secondaire", le programme affichera: 3 ème secondaire
                 Pour ch="Ali(BABA)marche, le programme affichera: Ali marche
1) faire une analyse du programme intitulé supprpar
2) deduire l'algorithme de cette analyse

1 Réponse

  • Bonsoir,
    si cela peut vous aider:
    CONST Faux = (0 = 1)
    CONST Vrai = NOT (Faux)
    DIM a AS STRING, b AS STRING, x AS INTEGER, c AS STRING
    a = "ceci (est) u(n (ess)ai bi(en (di)t) coucou)"
    c = a
    x = Vrai
    DO WHILE x
        PRINT c  
       x = SupprPar%(c, b)   
       c = b  
    LOOP
    END

    FUNCTION SupprPar% (w AS STRING, w1 AS STRING)
    DIM i AS INTEGER, j AS INTEGER, x2 AS INTEGER, ok AS INTEGER
    ok = Faux
    w1 = w
    x2 = 0
    FOR i = 1 TO LEN(w)
       IF MID$(w, i, 1) = ")" THEN
           x2 = i
           FOR j = x2 - 1 TO 1 STEP -1
                IF MID$(w, j, 1) = "(" THEN
                    w1 = ""
                    x1 = j
                    ok = Vrai
                    FOR k = 1 TO LEN(w)
                        IF NOT (x1 <= k AND k <= x2) THEN
                            w1 = w1 + MID$(w, k, 1)
                        END IF
                    NEXT k
                    EXIT FOR
                END IF
            NEXT j
        END IF
        IF ok THEN EXIT FOR
    NEXT i
    SupprPar% = ok
    END FUNCTION

    Image en pièce jointe de la réponse caylus

Autres questions