逆向输出

ikuaifenglea 2008-04-02 08:53:11
如何“this is a test”

把它逆向输出 ? 是 “siht si a tset”

如果给出全部逆向更好了

偶要代码哦

...全文
229 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
sheenl 2008-04-02
  • 打赏
  • 举报
回复
库函数strrev, 最简单,也最快
yananguo_1985 2008-04-02
  • 打赏
  • 举报
回复
用栈实现,先输入,遇到空格就输出栈.
lanmuyi 2008-04-02
  • 打赏
  • 举报
回复
while(没到字符串尾)
{
记录当前字符位置;
while(当前字符是空格)
{
字符入栈;
}
从刚才记录的位置开始字符全部出栈;
}

具体代码自己实现吧~
ttkk_2007 2008-04-02
  • 打赏
  • 举报
回复
部分逆向:分割每个单词,再逆向
全部逆向:直接逆向输出不就完了
ikuaifenglea 2008-04-02
  • 打赏
  • 举报
回复
[Quote=引用楼主 ikuaifenglea 的帖子:]
如何“this is a test”

把它逆向输出 ? 是 “siht si a tset”

如果给出全部逆向更好了

偶要代码哦
[/Quote]


我要的是 部分逆向啊

把它逆向输出 ? 是 “siht si a tset”
星羽 2008-04-02
  • 打赏
  • 举报
回复
支持小默~~~~~~~
Supper_Jerry 2008-04-02
  • 打赏
  • 举报
回复
#include <iostream>
using namespace std;
int main()
{
char str[] = "this is a test";
int len = strlen(str)-1;
for(int i = 0; i<=len/2; i++)
{
char c = str[i];
str[i] = str[len-i];
str[len-i] = c;
}
cout<<str<<endl;
return 0;
}
全部逆序。
vvpisces 2008-04-02
  • 打赏
  • 举报
回复
shy.............
LZ记得结帖
用户 昵称 2008-04-02
  • 打赏
  • 举报
回复
// test2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string.h>
#include <stdio.h>


char string[] = "this is a test";
char seps[] = " ,\t\n";
char *token;

void main( void )
{
printf( "%s\r\n", string );

token = strtok( string, seps );
while( token != NULL )
{
//printf( " %s\n", token );
int l = strlen( token );
for( int i = l - 1; i >= 0; i-- )
{
printf( "%c", *( token + i ) );
}
printf( "%c", 0x20 );
token = strtok( NULL, seps );
}
}
abupie 2008-04-02
  • 打赏
  • 举报
回复
用栈来做.
vvpisces 2008-04-02
  • 打赏
  • 举报
回复
试着写了一下,吼吼...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
int i;
char* src = "this is a test";
char* ptr = src + strlen(src) - 1;
for (i = strlen(src); i > 0; i--)
{
printf("%c", *ptr--);
}
system("pause");
return 0;
}
ikuaifenglea 2008-04-02
  • 打赏
  • 举报
回复
tset a si siht 恩
oo 2008-04-02
  • 打赏
  • 举报
回复
先读一个单词,然后逆向就行了。

全部逆向是什么意思?变成tset a si siht ?这样更容易
用户 昵称 2008-04-02
  • 打赏
  • 举报
回复
怎么叫全部逆向?
guocai_yao 2008-04-02
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 vvpisces 的回复:]
试着写了一下,吼吼...

C/C++ code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
int i;
char* src = "this is a test";
char* ptr = src + strlen(src) - 1;
for (i = strlen(src); i > 0; i--)
{
printf("%c", *ptr--);
}
system("pause");
return 0;
}
[/Quote]
不符合LZ要求

69,381

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧