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

字符串反转

时间:2014-10-11 00:42:44      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   for   sp   div   

 bubuko.com,布布扣

#define LOCAL
#include<cstdio>
#include<iostream>
using namespace std;
const int maxSize=10;
void REV(int R[],int b,int e)
{
    int i=b,j=e,temp;
    while(i<=j)
    {
        temp=R[i];
        R[i]=R[j];
        R[j]=temp;
        i++;
        j--;        
    }    
}
void Reverse(int R[],int m)
{
    REV(R,0,m);
    REV(R,m+1,maxSize);
    REV(R,0,maxSize);
}
void outPut(int R[],int n)
{
    int i=0;
    for(i=0;i<n;i++)
    {
        cout<<R[i]<<",";
    }
    cout<<endl;
}
int main()
{
#ifdef LOCAL
    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
#endif 
    int i,m,R[maxSize];
    for(i=0;i<maxSize;i++)
    {
        cin>>R[i];
    }
    cin>>m;
    outPut(R,maxSize);
    Reverse(R,m%maxSize);
    outPut(R,maxSize);
    return 0;
}

 

字符串反转

标签:style   blog   http   color   io   os   for   sp   div   

原文地址:http://www.cnblogs.com/jianfengyun/p/4017810.html

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