码迷,mamicode.com
首页 > 其他好文 > 详细

字符串倒序

时间:2015-06-06 13:20:21      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

#include <iostream>
#include <string>
using namespace std;

int main()
{
        char str[1024];
        cin>>str;
        int i = 0;
        while(str[i]!=\0)
        {
            i++;
        }
        int j= 0;
        int n=i;
        char str2[1024];
        for(j=0; j<n; j++)
        {
                str2[j]=str[i-1];
                i--;
        }
        str2[j] = \0;
        n=j;
        for(i=0,j=0; i<n;i++,j++)
        {
                str[i] = str2[j];
        }
        cout<<str<<endl;
        cout<<str2<<endl;
}

 

字符串倒序

标签:

原文地址:http://www.cnblogs.com/wystan/p/4556411.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!