字符串倒序

#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;
}

 

posted @ 2015-06-06 11:55  道心不可练  阅读(146)  评论(0编辑  收藏  举报