您的位置:首页 > 其它

字符串的逆序输出

2010-03-24 09:28 232 查看
曾经一个同事做过的一道笔试题,是涂鸭软件的,不知道是不是这样做的。。。

感觉太简单了???是不是没有领会它的意思呢???



// 字符串的逆序输出
#include "stdafx.h"
#include <stdio.h>     
#include <math.h>  
#include <iostream>
#include <String>
using namespace std;
int main()
{
	string str;
	
	cout<<"please input a string : "<<endl;
	getline(cin,str);
	int len = str.length();
	for(int i = len-1; i >= 0 ; i--)
	{
		cout<<str[i];
	}
	cout<<endl;
	system("pause");
}




真的真的,搞错了~



2.输入一个字符串,将其逆序后输出。(使用C++,不建议用伪码)
#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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: