首页 > 其他 > 详细

字符串逆序

时间:2020-03-26 14:36:15      阅读:58      评论:0      收藏:0      [点我收藏+]
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <Windows.h>

using namespace std;


int main() 
{
    char str[MAX_PATH];

    memset(str, 0, MAX_PATH);

    while (true)
    {
        cout << "input your string: " << endl;

        cin >> str;

        int len = strlen(str);

        for (int i = 0; i < (len + 1) / 2; i++)
        {
            char temp = str[i];

            str[i] = str[len - 1 - i];

            str[len - 1 - i] = temp;
        }

        cout << "result:" << str << endl;

        getchar();
    }
    
    return 0;
}

 

字符串逆序

原文:https://www.cnblogs.com/strive-sun/p/12574023.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!