Look And Say 序列 php

Lookandsay序列生成算法

Look and say 序列,因为每个元素通过查看前一个元素并说出其中是什么得来的。例如:查看第一个元素 1 ,你会说 “一个 1”,所以第二个元素就是 “11”。这就是两个 1 ,所以第三个元素是 “21”。类似的,这里有一个 2 和一个 1 ,所以第四个元素是 “1211”,以此类推。

代码实现:

function lookAndSay($s) {
    $r = '';              // 定义个返回结果的变量,初始化为空字符串
    $m = $s[0];           // $m 表示要统计的字符,初始化为字符串的第一个字符
    $n = 1;               // $n 表示已经查看过 $m 的个数,初始化为 1
    for($i = 1; $j = strlen($s); $i < $j; $i++) {
        if($s[$i] == $m) {
            // 如果当前的字符和上一个字符相同,统计这个字符的数量加 1
            $n++;
        }else {
            // 否则,拼接字符
            $r .= $n . $m;
            // 将要查找的字符设置为当前字符
            $m = $s[$i];
            // 重置统计字符的个数为 1
            $n = 1;
        }
    }
    // 最后一个数字需要在最后拼接到结果中
    return $r . $n . $m;
}


// 显示出前 10 个 Look And Say 序列
1
11
21
1211
111221
312211
13112221
1113213211
31131211131221
13211311123113112211
我在参加ctf新生赛,这是一道web题目,叫做ez??upload 给了一个网站http://160.30.231.222:33360/ 源代码是<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>Upload</title> <style> body { font-family: Arial, sans-serif; background-color: #f2f2f2; } .container { max-width: 400px; margin: 0 auto; padding: 20px; background-color: #fff; border-radius: 5px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); } .form-group { margin-bottom: 20px; } .form-group label { display: block; font-weight: bold; margin-bottom: 5px; } .form-group input[type="file"] { padding: 10px; border: 1px solid #ccc; border-radius: 5px; background-color: #fff; } .form-group input[type="submit"] { padding: 10px 20px; background-color: #4CAF50; color: #fff; border: none; border-radius: 5px; cursor: pointer; } .form-group input[type="submit"]:hover { background-color: #45a049; } </style> </head> <body> <div class="container"> <h2>文件上传</h2> <form action="index.php" method="POST" enctype="multipart/form-data"> <div class="form-group"> <label for="file">选择文件</label> <input type="file" name="file" id="file" /> </div> <div class="form-group"> <input type="submit" value="上传" /> </div> </form> </div> </body> </html> <!-- class.php --> Hacker? 把网站后缀加上/class.php得到<?php error_reporting(0); highlight_file(__FILE__); class hacker{ public $cmd; public $a; public function __destruct(){ if('hahaha' === preg_replace('/;+/','hahaha',preg_replace('/[A-Za-z_\(\)]+/','',$this->cmd))){ eval($this->cmd.'hahaha!'); } else { echo 'nonono'; } } } if(isset($_POST['file'])) { if(preg_match('/^phar:\/\//i',$_POST['file'])) { die("nonono"); } file_get_contents($_POST['file']); } ?> 我该怎么做才能找到flag,一步一步详细来讲,我是纯新手注意我是纯新手!
10-05
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值