1. 程式人生 > >翻轉單詞順序

翻轉單詞順序

tro public zab subst back logs include log 翻轉單詞

#include<stdio.h>
#include<string.h>
#include <pthread.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <stdlib.h>
#include <sstream>
using namespace std;


class Solution
{
public:
    string LeftRotateString(string str, int n)
    {
        int length=str.length();
        cout<<length<<endl;
        if(n>length)
            return str;
        else
        {
            string front=str.substr(0,n);
            string back=str.substr(n);
            back.append(front);
            return back;
        }
    }
};

int main()
{

    Solution s;
    string str="XYZabdfg";
    cout<<s.LeftRotateString(str,10)<<endl;
    system("pause");
    return 0;

}

翻轉單詞順序