zoukankan
html css js c++ java
字符串中单词逆序
/**/
/**/
/**/
/*
* 将字符串中单词出现次序逆序。
* "123 45 6" --->> "6 45 123"
*
* 对字符串扫描两次,第一次全体逆序,第二次以单词为单位逆序
*
*/
#include
<
stdio.h
>
#include
<
stdlib.h
>
#include
<
string
.h
>
char
*
reverse_string(
char
*
p, unsigned
int
size )
{
char
tmp;
unsigned
int
i;
if
( p
==
NULL
||
size
==
0
||
size
==
1
)
return
NULL;
i
=
0
;
while
( i
<
size
/
2
)
{
tmp
=
p[i];
p[i]
=
p[size
-
1
-
i];
p[size
-
1
-
i]
=
tmp;
i
++
;
}
return
p;
}
int
main(
void
)
{
char
buf[
100
]
=
"
1234567 1 1234 56
"
;
unsigned
int
buf_size;
unsigned
int
i;
unsigned
int
j;
buf_size
=
strlen( buf );
printf(
"
old string:\n%s\n
"
, buf );
reverse_string( buf, buf_size );
printf(
"
reversed first time:\n%s\n
"
, buf );
i
=
0
;
while
( i
<
buf_size )
{
//
skip spaces
while
( buf[i]
==
'
'
&&
buf[i]
!=
'
\0
'
)
{
i
++
;
}
j
=
i;
//
find nearest space
while
( buf[i]
!=
'
'
&&
buf[i]
!=
'
\0
'
)
{
i
++
;
}
//
now j point to the first character of
//
current word and i point to the nearest space
reverse_string(
&
buf[j], i
-
j );
}
printf(
"
reversed string:\n%s\n
"
, buf );
return
0
;
}
查看全文
相关阅读:
17、Semantic-UI之分页插件
16、Semantic-UI之模态窗口
15、Semantic-UI之导航
14、Semantic-UI之菜单样式
13、Semantic-UI之表格与表单
12、Semantic-UI之输入框
11、Semantic-UI之分割线
10、Semantic-UI之图片的使用
9、Semantic-UI之标题
8、Semantic-UI之其他按钮样式
原文地址:https://www.cnblogs.com/faraway/p/1243137.html
最新文章
使用cm-12.0源代码编译twrp
中文/英文双语言版本TWRP for Nexus5 -hammerheadcaf
安卓反汇编工具arm-eabi-objdump
用于编译cm-12.0 的 local_manifest.xml文件
树莓派安装 dig命令
dig for windows下载地址
使用CMakeLists.txt 判断编译器是否支持C++11
[转载] C++11新特性
ubuntu 防火墙关闭的80端口,开启方法
结构
热门文章
cocos2dx各个版本下载地址
eclipse运行错误提示 Failed to load D:Androidsdkuild-tools26.0.0-previewlibdx.jar
cvc-complex-type.2.4.d: 发现了以元素 'd:skin' 开头的无效内容。此处不应含有子元素。
烈焰遮天 cocos 手游mmo 源码 解析
Laravel查看当前已有的路由信息
在 Ubuntu 系统安装 Redi laravel 5.2 引入第三方类
一款你不容错过的Laravel后台管理扩展包 —— Voyager
ubuntu 安装mysql及目录位置
19、Semantic-UI之图片的动画效果
18、Semantic-UI之进度条
Copyright © 2011-2022 走看看