问题描述及代码:
/*
*烟台大学计算机与控制工程学院
*作 者:马赛
*完成日期:2016年10月20日
问题描述:试编写算法,实现将已知字符串所有字符倒过来重新排列。如ABCDEF改为FEDCBA。
输入描述:ABCDEF
程序输出:FEDCBA
*/
代码:
☆头文件及功能函数文件详见第八周项目1
☆main.cpp主函数代码
#include "sqstring.h"
void Invert(SqString &s)
{
int i;
char temp;
for (i=0; i<s.length/2; i++)
{
temp = s.data[i];
s.data[i]=s.data[s.length-i-1];
s.data[s.length-i-1] = temp;
}
}
int main()
{
SqString s;
StrAssign(s, "ABCDEF");
Invert(s);
DispStr(s);
return 0;
}
运行结果:
知识点总结:
运用了字符串的替换
学习心得:
对于字符串的操作有了新的认识。