字符串反转

 

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

 

posted @ 2014-10-10 21:06  剑风云  阅读(108)  评论(0编辑  收藏  举报