zoukankan      html  css  js  c++  java
  • 字符串右移n位(C++实现)

    字符串右移n位(C++实现):

    // ShiftNString.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    
    void Reverse(char* begin, char* end)
    {
        char temp;
        while(begin < end)
        {
            temp = *begin;
            *begin++ = *end;
            *end = temp;
            end --;
        }
    }
    void Shift(char* str,int n)
    {
        int nLen = strlen(str);
        Reverse(str,str + nLen - 1);    
        Reverse(str,str + n -1);
        Reverse(str + n, str + nLen -1);
    }
    int _tmain(int argc, _TCHAR* argv[])
    {
        char str[] = "123456789";
        Shift(str,3);
        cout << str <<endl;
        cin.get();
        return 0;
    }
  • 相关阅读:
    Swift
    Swift
    Swift
    Swift
    Swift
    Swift
    Swift
    C++生产和使用的临时对象
    RecyclerView0基于使用
    Docker创建MySQL集装箱
  • 原文地址:https://www.cnblogs.com/JczmDeveloper/p/3365295.html
Copyright © 2011-2022 走看看