Home > php教程 > php手册 > body text

PHP:统计两个数字中间有多少个回文数

WBOY
Release: 2016-06-06 20:09:15
Original
997 people have browsed it

所谓回文数,其实和回文字符串是一样,都是左往右看和从右往左看是一样的。所不同的是,一个是字符串,一个是数字。回文同是他们的特征。如果,你想知道,从999到999999999之间的回文数量,你会怎么处理呢,是数着呢,还是找别人一起数着呢。无疑地,不管人

所谓回文数,其实和回文字符串是一样,都是左往右看和从右往左看是一样的。所不同的是,一个是字符串,一个是数字。回文同是他们的特征。如果,你想知道,从999到999999999之间的回文数量,你会怎么处理呢,是数着呢,还是找别人一起数着呢。无疑地,不管人数的多少,这将是一个简单却又工作量巨大的事情。如果你真的遇上这样的问题了,那可以通过下面的代码进行处理:

<?php for($i=10;$i<100;$i++){   
       $len=strlen($i);   
       $l=1;   
       $k=intval($len)/2+1;   
     for($j=0;$j<$k;$j++){   
       if (substr($i,$j,1)!=substr($i,$len-$j-1,1))   
          $l=0;   
          break;   
  }   
if ($l==1)   
echo $i.&#8217;<br>’;   
}   
?>  
Copy after login

扩展阅读:《PHP:判断一个字符串是否为回文字符串》

转载请注明:IT路人 » PHP:统计两个数字中间有多少个回文数

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!