ajout
This commit is contained in:
parent
cdc8b35d82
commit
1d5a10f14d
84
romanToNumber/convertisseurYvette.php
Normal file
84
romanToNumber/convertisseurYvette.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
//convertir un nombre romain en nombre arabe
|
||||
|
||||
|
||||
function base($char)
|
||||
{
|
||||
if($char === 'I') return 1;
|
||||
|
||||
elseif($char === 'V') return 5;
|
||||
|
||||
elseif($char === 'X') return 10;
|
||||
elseif($char === 'L') return 50;
|
||||
elseif($char === 'C') return 100;
|
||||
elseif($char === 'D') return 500;
|
||||
elseif($char === 'M') return 1000;
|
||||
}
|
||||
|
||||
function Convertir($nbreRomain)
|
||||
{
|
||||
$resultat =array();
|
||||
$somme=0;
|
||||
$reference;
|
||||
|
||||
if(strlen($nbreRomain)===1)
|
||||
{
|
||||
|
||||
$somme=base($nbreRomain);
|
||||
return $somme;
|
||||
}
|
||||
elseif(strlen($nbreRomain)>1)
|
||||
{
|
||||
for($j=0; $j<strlen($nbreRomain); $j++ )
|
||||
{
|
||||
|
||||
$resultat[]=base($nbreRomain[$j]);
|
||||
|
||||
}
|
||||
|
||||
$i=0;
|
||||
while(sizeof($resultat)!=0)
|
||||
{
|
||||
if(isset($resultat[$i+1])){
|
||||
if($resultat[$i] === $resultat[$i+1])
|
||||
{
|
||||
$somme+=$resultat[$i]+$resultat[$i+1];
|
||||
array_splice($resultat,0,2);
|
||||
|
||||
}
|
||||
|
||||
elseif($resultat[$i] < $resultat[$i + 1])
|
||||
{
|
||||
$somme+=$resultat[$i+1] - $resultat[$i];
|
||||
array_splice($resultat,0,2);
|
||||
|
||||
}
|
||||
|
||||
elseif($resultat[$i] > $resultat[$i+1])
|
||||
{
|
||||
$somme+= $resultat[$i];
|
||||
array_splice($resultat,0,1);
|
||||
|
||||
}
|
||||
}
|
||||
else{
|
||||
$somme+=$resultat[$i];
|
||||
$resultat=array();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $somme;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
43
romanToNumber/interfaceYvette.php
Normal file
43
romanToNumber/interfaceYvette.php
Normal file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Convertisseur Nombre Romain en Nombre Arabe</title>
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
<script type='text/javascript' >
|
||||
document.queryse
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php
|
||||
|
||||
require_once("convertisseurYvette.php");
|
||||
|
||||
?>
|
||||
<div class="card mx-auto mt-5 bg-warning" style="width: 40rem;">
|
||||
|
||||
<div class="card-body">
|
||||
<form class="container " action="" method="post">
|
||||
<div class="form-group row">
|
||||
<label for="Romain" class="col-6 text-right">Nombre Romain</label>
|
||||
<input type="text" class="form-control col-6" id="Romain" placeholder="Entre un nombre romain" name=romain value="<?php if($_POST) echo $_POST['romain'];?>">
|
||||
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="Arabe" class="col-6 text-right">Nombre Arabe</label>
|
||||
<input type="text" class="form-control col-6" id="Arabe" value="<?php if($_POST) echo Convertir($_POST['romain']);?>">
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-danger" >Convertir</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user