Rita li

You give me a future, I love you the whole once

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
//字符串倒置
#include <iostream> 
#include<string>
using namespace std;
int main()  
{
    string str;
    while(cin>>str)
    {
      int l=str.length();
      for(int j=l-1;j>=0;j--)
        cout<<str[j];
      cout<<endl;
    }
    return 0; 
}
/*方法2
#include <iostream>
#include <string>
using namespace std;

void reverse(string &str)
{
    int l=str.length();
    for(int i=0;i<l/2;i++)
    {
        char c=str[i];
        str[i]=str[l-i-1];
        str[l-i-1]=c;
    }
}

int main()
{
    string a;

    while(cin>>a)
    {
    reverse(a);
    cout<<a<<endl;
    }
    return 0;
}*/

 

posted on 2014-03-30 15:46  Rita li  阅读(359)  评论(0编辑  收藏  举报