str_翻转字符串
1. 给一个句子,翻转每个单词,单词内部不翻转
$str = "dog loves pig";
$ret = turnSentence($str);
var_dump($ret);
function turnSentence($str1)
{
$str2 = turnWord($str1);
$str2_arr = explode(' ', $str2);
foreach ($str2_arr as $key => &$value) {
$value = turnWord($value);
}
unset($value);
return implode(' ', $str2_arr);
}
function turnWord($str) // 用php处理字符串函数strrev更优
{
$length = strlen($str);
$ret = '';
for ($i = $length - 1; $i >= 0; $i--) {
$ret .= $str{$i};
}
return $ret;
}
输出结果: pig loves dog
str_翻转字符串的更多相关文章
- [LeetCode] Reverse Vowels of a String 翻转字符串中的元音字母
Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...
- [LeetCode] Reverse Words in a String 翻转字符串中的单词
Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...
- [CareerCup] 1.2 Reverse String 翻转字符串
1.2 Implement a function void reverse(char *str) in C or C++ which reverses a null-terminated string ...
- lintcode :Reverse Words in a String 翻转字符串
题目: 翻转字符串 给定一个字符串,逐个翻转字符串中的每个单词. 样例 给出s = "the sky is blue",返回"blue is sky the" ...
- [LeetCode] Reverse Words in a String III 翻转字符串中的单词之三
Given a string, you need to reverse the order of characters in each word within a sentence while sti ...
- [LeetCode] Reverse String II 翻转字符串之二
Given a string and an integer k, you need to reverse the first k characters for every 2k characters ...
- [Swift]LeetCode151. 翻转字符串里的单词 | Reverse Words in a String
Given an input string, reverse the string word by word. Example: Input: "the sky is blue", ...
- C#版(击败100.00%的提交) - Leetcode 151. 翻转字符串里的单词 - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C#版 - L ...
- LeetCode 151 翻转字符串里的单词
题目: 给定一个字符串,逐个翻转字符串中的每个单词. 示例 1: 输入: "the sky is blue" 输出: "blue is sky the" 示例 ...
随机推荐
- 【杭州图铭科技有限公司招募贴】——“JUST DO IT”
I'm convinced that the only thing that kept me going was that I loved what I did. ——Steve Paul Jobs( ...
- logstash 安装zabbix插件
<pre name="code" class="html">[root@xxyy yum.repos.d]# yum install ruby Lo ...
- redis maxmemory设置
关于maxmemory的设置,如果redis的应用场景是作为db使用,那不要设置这个选项,因为db是不能容忍丢失数据的. 如果作为cache使用,则可以启用这个选项(其实既然有淘汰策略,那就是cach ...
- 【转】 ubuntu12.04更新源
原文网址:http://blog.chinaunix.net/uid-26404477-id-3382633.html 摘 要:本文列出ubuntu 12.04 LTS更新源列表,内容为网友整理,此处 ...
- 新闻:型牌男装:网上订服装,如何将返修率降到5个点以下 | IT桔子
新闻:型牌男装:网上订服装,如何将返修率降到5个点以下 | IT桔子 型牌男装:网上订服装,如何将返修率降到5个点以下
- java对象在hibernate持久层的状态
站在持久化层的角度,一个java对象在它的生命周期中,可处于以下4个状态之一: 临时状态(transient):刚刚用new语句创建,还没有被持久化,并且不处于Session的缓存中. 持久化状态(p ...
- Ubuntu 无线连接能上网,但是有线连接不能上
这两天装Ubuntu,遇到小问题.最头疼的还是上网,过去我装了Ubuntu时,都是插上网线就能直接上网,这次就不行了. 我刚点开一个网页,接下来点就不能上了,但是无线连接就可以正常上网. 我在一个论坛 ...
- Java中的enum
package com.st.java; /** * ENUM枚举类型的使用 * @author Administrator * 2016年04月10日 */ public enum MoneyTyp ...
- 【转】TI蓝牙BLE 协议栈代码学习
BLE就是低功率蓝牙.要着重了解两种设备: dual-mode双模设备:简单说就是向下兼容. single-mode单模设备:仅仅支持BLE. 关于开发主要讲的是单模设备,它可以只靠纽扣电池即可持 ...
- STL采用的标准模板库
一.map,set set集合容器实现了红黑树(Red-Black Tree)的平衡二叉检索树的数据结构,在插入元素时,它会自动调整二叉树的排列,把该元素放到适当的位置,以确保每个子树根节点的键值大于 ...