92 lines
2.9 KiB
COBOL
92 lines
2.9 KiB
COBOL
IDENTIFICATION DIVISION.
|
||
PROGRAM-ID. palind.
|
||
AUTHOR. OD.
|
||
*-------------------------------------------*
|
||
* PROGRAMME DE VERIFICATION D'UN PALINDROME *
|
||
*-------------------------------------------*
|
||
|
||
ENVIRONMENT DIVISION.
|
||
DATA DIVISION.
|
||
|
||
WORKING-STORAGE SECTION.
|
||
*--------------------------*
|
||
* DEFINITION DES VARIABLES *
|
||
*--------------------------*
|
||
* LE MOT DONNE PAR L'UTILISATEUR
|
||
77 MOT PICTURE X(255) VALUE SPACE.
|
||
* RESULTAT DU PROGRAMME (ICI ON DIRA "CECI EST UN PALINDROME")
|
||
* OU PAS)
|
||
77 RESULTAT PICTURE X(30) VALUE SPACE.
|
||
* DEBUT-MOT ET DBUT-FIN SUBISSENT UNE INCREMENTATION
|
||
* CE SONT LES CURSEURS
|
||
77 DEBUT-MOT PICTURE 99 VALUE 1.
|
||
77 FIN-MOT PICTURE 99 VALUE 30.
|
||
* LETTREG CONTIENDRA UNE LETTRE DU MOT, CELLE COTE GAUCHE
|
||
* LETTRED, CELLE COTE DROITE
|
||
77 LETTREG PICTURE X VALUE SPACE.
|
||
77 LETTRED PICTURE X VALUE SPACE.
|
||
* DEFINITION DE QUELQUES VALEUR NUMERIQUES
|
||
* POUR LES CONTROLES
|
||
01 ETUDE-ENONCE.
|
||
05 COMP-VALID PICTURE 9 VALUE 1.
|
||
88 COMP-CORRECT VALUE 1.
|
||
05 CARAC-DEB PICTURE 9 VALUE 1.
|
||
88 CARACD-CORRECT VALUE 1.
|
||
05 CARAC-FIN PICTURE 9 VALUE 1.
|
||
88 CARACF-CORRECT VALUE 1.
|
||
|
||
PROCEDURE DIVISION.
|
||
*NOM DU PROGRAMME
|
||
PRINCIPAL SECTION.
|
||
|
||
DEBUT.
|
||
PERFORM SAISIE.
|
||
CORPS.
|
||
PERFORM TRAITER.
|
||
FIN.
|
||
DISPLAY RESULTAT.
|
||
DISPLAY "FIN DU TRAITEMENT".
|
||
STOP RUN.
|
||
|
||
*SAISIE DU MOT
|
||
SAISIR SECTION.
|
||
SAISIE.
|
||
DISPLAY "Saisissez une phrase : " WITH NO ADVANCING.
|
||
ACCEPT MOT.
|
||
*------*
|
||
* TEST *
|
||
*------*
|
||
DISPLAY MOT.
|
||
|
||
*TRAITEMENT DE LA PHRASE
|
||
TRAITEMENT SECTION.
|
||
TRAITER.
|
||
PERFORM COMPARER UNTIL NOT COMP-CORRECT.
|
||
*VALIDE IS NOT EQUAL TO 1.
|
||
|
||
*COMPARAISON DE LA CHAINE DE CARACT<43>RE
|
||
COMPARER.
|
||
DISPLAY DEBUT-MOT.
|
||
DISPLAY FIN-MOT.
|
||
* PERFORM PARCOURS-FIN UNTIL NOT CARACF-CORRECT.
|
||
MOVE ZERO TO COMP-VALID.
|
||
|
||
*PARCOURS DE LA CHAINE DE FIN
|
||
PARCOURS-FIN.
|
||
DISPLAY "DERNIERE LETTRE DU MOT : " MOT(FIN-MOT:1).
|
||
IF (MOT(FIN-MOT:1) EQUAL TO SPACE) THEN
|
||
SUBTRACT 1 FROM FIN-MOT
|
||
ELSE MOVE 1 TO CARAC-FIN
|
||
END-IF.
|
||
* MOVE MOT(FIN-MOT:1) TO LETTRE.
|
||
* PERFORM CAL-CHFFRE UNTIL LETTRE NOT EQUAL TO SPACE.
|
||
* IF (MOT(DEBUT-MOT:1) EQUAL TO MOT(FIN-MOT:1))
|
||
* MOVE 1 TO VALIDE
|
||
* END-IF.
|
||
|
||
*CALCUL DU CHIFFRE DE LA LETTRE <20> COMPARER
|
||
CAL-CHFFRE.
|
||
IF (MOT(FIN-MOT:1) EQUAL TO SPACE) THEN
|
||
SUBTRACT 1 FROM FIN-MOT
|
||
END-IF.
|