东京大学ime项目官网:先谢谢大侠了,急急急.!!用C编一小程序.(字符串的倒序输出)

来源:百度文库 编辑:中科新闻网 时间:2024/04/28 23:33:43
Implement a revert function which takes a string as input, on output, it reverts the characters in the input string. e.g. "Hello" becomes "olleH"

char * revert ( char * s )
{

}

/*...*/

#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

const int SIZE = 100;
void revert(char *s);

int main()
{
char str[SIZE];
cout << "input a string:\n";
cin.getline(str,SIZE);

revert(str);

cout << "After reverting the string it becomes " << endl
<< str << endl;

system("PAUSE");
return 0;
}

void revert(char *s)
{
char temp;
for (int i=0,j=strlen(s)-1; i<j; ++i,--j)
{
temp = s[i];
s[i] = s[j];
s[j] = temp;
}

}

这样行不行?
对不起啊写网页习惯咧! 汗~~很长时间没用c写程序了~~
这里调用了三个函数几乎是最复杂的方法你可以尝试递归函数
这里就不多写了也不注释了网上资源很多你可以自己找找学会了自己自然就会用以上方法编了.

..那不是C++了么..
不过改下就行了吧 呵呵 不太明白
自己编了有一会了 弄迷糊了..

你们好厉害哦