设为首页 加入收藏

TOP

C++面试题字符串逆序
2011-04-18 12:29:21 来源: 作者: 【 】 浏览:742
Tags:试题 字符串

Q:输入一个字符串,将其逆序后输出。(使用C++(www.cppentry.com),不建议用伪码)

#include <iostream>
using namespace std;


void main()
{
  char a[50];memset(a,0,sizeof(a));
  int i=0,j;
  char t;
  cin.getline(a,50,'\n');
  for(i=0,j=strlen(a)-1;i<strlen(a)/2;i++,j--)
  {
   t=a[i];
      a[i]=a[j];
   a[j]=t;
  }
  cout<<a<<endl;  
}

//第二种

string str;
cin>>str;
str.replace;
cout<<str;

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++面试-内存管理方法 下一篇C++面试题