Skip to content

Instantly share code, notes, and snippets.

View drunkday's full-sized avatar

HanLin drunkday

  • In the waves
View GitHub Profile
@drunkday
drunkday / RemoveMultipleSpaces.cs
Created March 29, 2012 10:32 — forked from Ninputer/RemoveMultipleSpaces.cs
模拟微面试之去空格
//请实现下面的函数,输入参数baseStr是一个(可以更改的)字符串,请将其中所有连续出现的多个空格都替换成一个空格,单一空格需保留。
//请直接使用baseStr的空间,如需开辟新的存储空间,不能超过o(N)(注意是小o,N是字符串的长度)。返回值是替换后的字符串的长度。
//样例代码为C#,但可以使用任何语言。如需使用任何库函数,必须同时给出库函数的实现。
class Program
{
public static int RemoveMultipleSpaces(char[] baseStr)
{
// TODO
}
}
@drunkday
drunkday / RemoveSpace.php
Created March 30, 2012 05:36
PHP一个去空格的代码
<?php
function RemoveSpace($str){
/* 获取字符串长度/转为循环次数 */
$l=strlen($str);
for($i=0;$i<$l;$i++){
/* 判断如果当前字符和下一个字符为空格,则当前字符为NUll */
if($str[$i] == ' ' and $str[$i+1] == ' '){
$str[$i] = '';
}
}
@drunkday
drunkday / up.php
Created October 11, 2012 03:01
中文数字转化大写
<?php
function trans($str){
$str = ltrim($str,"0") * 1;
$str = (string)$str;
$Big = array(0=>"",1=>"壹",2=>"贰",3=>"叁",4=>"肆",5=>"伍",6=>"陆",7=>"柒",8=>"捌",9=>"玖");
$loc = array(0=>"零",1=>"",2=>"拾",3=>"佰",4=>"仟");
$level = array("","万","亿","兆");
$result = NULL;
$len = ceil(strlen($str)/4);
$l = strlen($str)-1;