一道百度2014校招笔试题


题目:用c/c++,不借助任何系统函数,实现字符串的反转,如输入apple,输出elppa

#include "stdafx.h"
#include<iostream>
using namespace std;

void swap(char c1, char c2)
{
	char c = c1;
	c1 = c2;
	c2 = c;
}

void reverse(char *s)
{
	int count = 0 ;
	if(s=="")
		return;
	while(s[count] != '\0')
	{
		count ++;
	}
	int i = 0 , j = count - 1;
	while(i < j)
	{
		char c = s[i];
		s[i] = s[j];
		s[j] = c;
		i ++ ;
		j --;
	}
}



int main(int argc, char* argv[])
{
	char s[] = "123456";
	reverse(s);
	cout<<s<<endl;
	

	return 0;
}

你可能感兴趣的:(一道百度2014校招笔试题)