码上爬 第17题

<?php
$headers[]='Cookie:Hm_lvt_0d2227abf9548feda3b9cb6fddee26c0=1753770435; HMACCOUNT=6C5FAAD55F97CCBA; sessionid=igh1biz81ycba75qahqu34l4dagundyc; Hm_lpvt_0d2227abf9548feda3b9cb6fddee26c0=1753777391';
$headers[]='Referer:https://www.mashangpa.com/problem-detail/3/';
$headers[]='User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.95 Safari/537.36';

//echo get_num();exit;


$num=0;
for($i=1;$i<=20;$i++){
    $url = 'https://www.mashangpa.com/api/problem-detail/17/data/?page='.$i;
    $code = get_curl_contents($url,$headers);
    //echo $code;exit;
    $json = json_decode($code,true);
    $sum=0;
    foreach($json['current_array'] as $v){
        $sum+=get_num($v);
    }
    //echo $sum;
    $num+=$sum;
}

echo $num;



function get_total_millisecond() {
    $time = explode(" ", microtime());
    $time = ($time[1] + $time[0]) * 1000;
    $time = round($time) . '';
    return $time;
}

function get_curl_contents($bstrURL, $headers = null, $post = null) {
    $ch = curl_init($bstrURL);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    if ($headers) {
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    }
    if ($post) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }
    $data = curl_exec($ch);
    // 关闭CURL会话
    curl_close($ch);
    return $data;
}


function get_num($str='સধન'){
    $list = [
        'ꙮ' =>  '0',
        'ઊ' =>  '1',
        'સ' =>  '2',
        'ત' =>  '3',
        'ধ' =>  '4',
        'ન' =>  '5',
        'પ' =>  '6',
        'ફ' =>  '7',
        'બ' =>  '8',
        'ભ' =>  '9'
    ];

    $length = mb_strlen($str, 'UTF-8');
    $result = '';
    for ($i = 0; $i < $length; $i++) {
        $temp = mb_substr($str, $i, 1, 'UTF-8');
        $result .= $list[$temp];
    }
    return intval($result);
}
none
最后修改于:2025年08月03日 17:09

添加新评论