コード例 #1
0
ファイル: etna_movies.php プロジェクト: antoineMo/E_Movies
function del_student($argv)
{
    if (!isset($argv[2])) {
        echo "Pas assez d'argument\n";
        return 0;
    }
    $connect = new MongoClient();
    $db = $connect->db_etna;
    $collection = $db->students;
    $cursor = $collection->findOne(array("login" => $argv[2]));
    if (isset($cursor)) {
        echo "Are you sure ? oui/non\n> ";
        $str = readLine();
        if (strcmp($str, "oui") == 0 || strcmp($str, "yes") == 0) {
            $collection->remove(array('login' => $argv[2]));
            echo "L'utilisateur a été supprimé\n";
        } else {
            if (strcmp($str, "non") == 0 || strcmp($str, "no") == 0) {
                echo "L'utilisateur n'a pas été supprimé\n";
            } else {
                echo "Commande incorrect !\n\n";
                del_student($argv);
            }
        }
    } else {
        echo "Cet utilisateur n'est pas enregistré !\n";
    }
}
コード例 #2
0
ファイル: verif_movie.php プロジェクト: antoineMo/E_Movies
function verif_phone()
{
    $str = readLine();
    while (preg_match_all("/^0[1-68]([-. ]?[0-9]{2}){4}\$/", $str) == 0) {
        echo "Numéro invalide !\n> ";
        $str = readLine();
    }
    return $str;
}
コード例 #3
0
ファイル: other_func.php プロジェクト: antoineMo/E_Movies
function update_student($argv)
{
    if (isset($argv[2]) && preg_match_all("/[a-z]{6}_[a-z0-9]/", $argv[2], $array)) {
        echo "What do you want to update? \n> ";
        $str = readLine();
        $up = verif_update($str);
        if ($up != 0) {
            $connect = new MongoClient();
            $db = $connect->db_etna;
            $collection = $db->students;
            $newdata = array('$set' => array($str => $up));
            $collection->update(array("login" => $argv[2]), $newdata);
            echo "User informations modified !";
        }
    } else {
        echo "Login incorrect !\n";
    }
}
コード例 #4
0
ファイル: factorial.php プロジェクト: Amina24/Boot-Camp
<?php

class factorial
{
    function fact($num)
    {
        $f = 1;
        for ($i = 1; $i <= $num; $i++) {
            $f = bcmul($f, $i);
        }
        echo (double) $f;
        echo number_format($f, 0, '', '');
        printf("Factorial  %0.0lf \n", $f);
        return $f;
    }
}
$amina = new factorial();
$num = readLine("Enter Number : ");
$amina->fact($num);
echo $amina->fact($num - 1) * $num;
コード例 #5
0
ファイル: conditions.php プロジェクト: windmill654/General
<?php

// only works for php interpreter
// type in cmd line:
// php conditions.php
$n = readLine("Please give a number: ");
if ($n > 0) {
    printf("You picked a positive number!\n");
} else {
    if ($n == 0) {
        printf("You picked zero!\n");
    } else {
        if ($n < 0) {
            printf("You picked a negative number!\n");
        }
    }
}
コード例 #6
0
<?php

$statusPadding = 0;
preg_match_all("/Columns:[ \t]+([0-9]+)/", `mode`, $matches);
$MAX_LENGTH = (int) $matches[1][0] - 1;
$MAX_LENGTH = 180;
$input = trim(readLine("Plugin dir name: "), "/\\");
if (!is_dir($input)) {
    fail("Directory doesn't exist!");
}
$dir = rtrim(realpath($input), "/\\") . "/";
if (!is_dir($srcDir = $dir . "src/")) {
    fail("Source folder not found!");
}
if (!is_dir($dir . "bin")) {
    console("Creating bin/ directory and its README file...");
    mkdir($dir . "bin");
}
$path = $dir . "bin/" . $input . ".phar";
if (is_file($path)) {
    console("Older phar detected, deleting...");
    unlink($path);
}
console("Creating phar at {$path}...");
$phar = new Phar($path);
$phar->setStub('<?php __HALT_COMPILER();');
$phar->setSignatureAlgorithm(Phar::SHA1);
$phar->startBuffering();
console("Adding files into phar...");
clearLine();
console("Adding sources...");
コード例 #7
0
ファイル: Bigger.php プロジェクト: Amina24/Boot-Camp
class Greater
{
    function Bigger($str)
    {
        $len = strlen($str);
        for ($i = 0; $i < $len; $i++) {
            $arr[] = ord($str[$len]);
        }
        $len = -2;
        for (; $len >= 0; $len--) {
            $ch1 = ord($str[$len]);
            $ch2 = ord($str[$len - 1]);
            if ($ch1 > $ch2) {
                $temp = $str[$len];
                $str[$len] = $str[$len - 1];
                $str[$len - 1] = $temp;
                echo $str . "\n";
                return;
            }
        }
        echo "no answer \n";
    }
}
$amina = new Greater();
$count = readLine("Total Words:  ");
for ($i = 0; $i < $count; $i++) {
    $word[] = readLine("\nWord : ");
}
for ($i = 0; $i < $count; $i++) {
    $amina->Bigger($word[$i]);
}
コード例 #8
0
    return "./index/{$code}/_result_{$code}.log";
}
?>


<?php 
$temp_file = "./c_p";
$c_p_array = array();
$p_c_array = array();
//单key多值数组
$class = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J");
//$class = array("A");
foreach ($class as $c) {
    $path = get_file_path($c);
    $fp = fopen($path, "r");
    while ($line = readLine($fp)) {
        $arr = explode(" ", $line);
        if (count($arr) != 2) {
            continue;
        }
        $line = $arr[0];
        $arr = explode("#", $line);
        $len = count($arr);
        for ($i = 1; $i < $len; $i++) {
            $c_p_array[$arr[$i]] = $arr[$i - 1];
        }
        $p_c_array[$arr[$len - 1]] = array();
        //最后一个是叶子节点,下面就是具体文章了
    }
    fclose($fp);
}
コード例 #9
0
ファイル: campers.php プロジェクト: Amina24/Boot-Camp
<?php

class campers
{
    function snipers($arr, $K)
    {
        $sp = 0;
        for ($i = 1; $i < $K; $i++) {
            $diff = $arr[$i] - $arr[$i - 1] - 3;
            if ($diff > 0) {
                $sp += ceil($diff / 2.0);
            }
            // echo $sp;
        }
        echo $sp;
    }
}
$amina = new campers();
$N = readLine("Total Players: ");
$K = readLine("Snipers :");
for ($i = 0; $i < $K; $i++) {
    $snip[] = readLine("Sniper Position : ");
}
$amina->snipers($snip, $K);
コード例 #10
0
ファイル: funnystr.php プロジェクト: Amina24/Boot-Camp
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
class FunnyStr
{
    function funny($str)
    {
        // echo $str;
        $str1 = strrev($str);
        //echo $str1;
        $len = strlen($str);
        for ($i = 1; $i < $len;) {
            if (abs(ord($str[$i]) - ord($str[$i - 1])) == abs(ord($str1[$i]) - ord($str1[$i - 1]))) {
                $i++;
            } else {
                echo "not funny";
                return;
            }
        }
        echo "funny";
    }
}
$ab = new funnyStr();
$count = readLine("how many times : ");
for ($i = 1; $i < $count + 1; $i++) {
    $word[] = readLine("Word" . $i . " :  ");
}
for ($i = 0; $i < $count; $i++) {
    $ab->funny($word[$i]);
}
?>
      
コード例 #11
0
ファイル: candies.php プロジェクト: Amina24/Boot-Camp
    function get_candy($arr, $count, $candy)
    {
        if ($arr[0] > $arr[1]) {
            $candy[0] += 1;
        }
        for ($i = 1; $i < $count - 1; $i++) {
            if ($arr[$i] > $arr[$i + 1]) {
                $candy[$i] += 1;
            }
            if ($arr[$i] > $arr[$i - 1]) {
                $candy[$i] += 1;
            }
        }
        if ($arr[$count - 1] > $arr[$count - 2]) {
            $candy[$count - 1] += 1;
        }
        print_r($arr);
        print_r($candy);
        for ($i = 0, $sum = 0; $i < $count; $i++) {
            $sum += $candy[$i];
        }
        echo $sum;
    }
}
$amina = new candies();
$count = readLine("Children : ");
for ($i = 1; $i < $count + 1; $i++) {
    $candy[] = 1;
    $rate[] = readLine(" Rating of child " . $i);
}
$amina->get_candy($rate, $count, $candy);
コード例 #12
0
function get_docs_by_classpath($class, $classpath, $baseInfo)
{
    $title_detail_url_map = get_title_detail_map($class, $classpath);
    $index_url_map = get_index_url_map($class, $classpath);
    $docs = array();
    $path = "./data/" . $class;
    $file_list_of_class = $path . "/" . $classpath . ".log";
    $tmp = iconv("utf-8", "gb2312//IGNORE", $file_list_of_class);
    if (!file_exists($tmp)) {
        echo $file_list_of_class . " NOT FOUND\n";
        save("logs/detail_not_found.txt", $path . "\n", "a+");
        return $docs;
    }
    $fp = fopen($tmp, "r+");
    while ($line = readLine($fp)) {
        if (strlen($line) == 0) {
            continue;
        }
        $arr = explode("\t", $line);
        $doc = array();
        $doc = array_merge($doc, $baseInfo);
        $title = $doc['title'] = $arr[0];
        $doc['author'] = $arr[1];
        $doc['school'] = $arr[2];
        $doc['degree'] = $arr[3];
        $doc['year'] = $arr[4];
        $doc['read_url'] = $arr[5];
        $doc['abstract_302_url'] = $arr[6];
        $c = $doc['code'] = $arr[7];
        $doc['status'] = 0;
        $doc['_id'] = md5($c . $title);
        $doc['abstract_url'] = @$title_detail_url_map[$title];
        $doc = array_merge($doc, get_abstract_by_title($class, $classpath, $title));
        //$doc = array_merge($doc, get_index($class, $classpath, $title));
        $doc['index'] = get_index($class, $classpath, $title);
        $doc['index_url'] = isset($index_url_map[$title]) ? $index_url_map[$title] : "";
        $doc['ts'] = time();
        $docs[] = $doc;
    }
    fclose($fp);
    //exit;
    return $docs;
}
$square = "Square";
$rectangle = "Rectangle";
$triangle = "Triangle";
$circle = "Circle";
$help = "Help";
$quit = "Quit";
echo "\nType 'Quit' to exit program when desired.\n";
$ask = readline("Input the shape to calculate its area. (Please have first letter be uppercase): ");
if ($ask == $quit) {
    echo "You have quit.\n\n";
}
while ($ask != $quit) {
    if ($ask == $square) {
        // creates square image
        echo " __________\n?          |\n?          |\n?          |\n?          |\n?__________|\n";
        $squareside1 = readLine("What is the length of one of its sides? ");
        // get side length
        $squareanswer = $squareside1 * $squareside1;
        // calculates area of square
        //creates square image for saying area
        echo "\n __________\n|          |\n|          |\n|          |\n|          |\n|__________|\n\n";
        echo "The area of the square is: " . $squareanswer;
        $ask = readline("\n\nInput a shape to calculate its area: ");
        // prompts user to continue
    }
    if ($ask == $rectangle) {
        // creates rectangle image
        echo " _______________\n|               |\n|               |\n|               |\n ? ? ? ? ? ? ? ?\n";
        $rectangleside1 = readline("What is the length of its base? ");
        // finds base
        echo " _______________\n?               |\n?               |\n?               |\n?_______________|\n";
コード例 #14
0
ファイル: start.php プロジェクト: Amina24/Boot-Camp
 public function profile($user)
 {
     echo $user->u_id;
     //.",".$user->name.",".$user->phone_no.",".$user->email.",".$user->password.",".$user->tweet;
     echo "**********  Welcome " . $user->name . " ***********\n\n";
     //	echo "*********  Your total Tweets  ".$user->tweet. "   *******";
     do {
         echo "\n    ***** Press 1 to show all Tweets. *****\n";
         echo "    ***** Press 2 for your Tweets *****\n";
         echo "    ***** Press 3 Settings  *****  \n";
         echo "    ***** Press 4 for Add Tweet  *****  \n";
         echo "    ***** Press 5 for Logout  *****  \n";
         echo "    ***** Ente ur choice :   ";
         $choice = readLine();
         $t = new Tweet();
         switch ($choice) {
             case "1":
                 $tweets = $t->all_tweets();
                 $this->display_tweets($tweets);
                 break;
             case "2":
                 $tweets = $t->all_tweets($user->u_id);
                 $this->display_tweets($tweets);
                 break;
             case "3":
                 $this->settings($user->u_id);
                 break;
             case 4:
                 $t->message = $this->input("Message for Tweet ");
                 echo $t->date = date("d-m-y");
                 echo $t->time = date("h:i:sa");
                 $t->u_id = $user->u_id;
                 $t->add_tweet();
                 echo "Successfully Added ";
                 break;
             case 5:
                 echo " --------------    ALLAH Hafiz  ----------------\n ";
                 return;
             default:
                 echo "\n\n**********  Do Enter wrong input try again ***********\n\n";
         }
     } while (24);
 }
コード例 #15
0
ファイル: task25_1.php プロジェクト: royki/codingame-traning
<?php

// Doctor Who
function readLine()
{
    $line = fgets(STDIN);
    return substr($line, 0, strlen($line) - 1);
}
list($w, $h) = explode(' ', readLine());
$in = explode(' ', readLine());
$ar = array();
$x = 0;
$y = 0;
for ($i = 0; $i < count($in); $i += 2) {
    $col = $in[$i] == 'W' ? 0 : 1;
    for ($j = 0; $j < $in[$i + 1]; $j++) {
        if (!isset($ar[$y])) {
            $ar[$y] = array();
        }
        $ar[$y][$x] = $col;
        $x++;
        if ($x == $w) {
            $x = 0;
            $y++;
        }
    }
}
for ($x = 0; $x < $w; $x++) {
    for ($y = 0; $y < $h; $y++) {
        if ($ar[$y][$x]) {
            $line0 = $y;