The Problem:Your job is, inverting an input string,

Sample Input:abcde
Output:edcba

Here is an example to solve this problem in C++:

#include <iostream>
#include <string.h>
#define MAX_SIZE 256
using namespace std;

int main(){
    char input[MAX_SIZE];

    cout << "Input a String to inverse: ";

    cin.getline(input,MAX_SIZE);
    int input_Size = strlen(input);

    cout << "Before String inverse: " << input;

    for(int i = 0;i < input_Size/2; i++){
        char temp;
        temp = *(input+(input_Size-i-1));
        *(input+(input_Size-i-1)) = *(input+i);
        *(input+i) = temp;
    }

    cout << "After String inverse: " << input;
    return 0;
}

Written by 

城市裡的小小迷僮工程師,喜歡用鍵盤記錄個人生活的點滴,身邊的人事物都我的靈感,用心踏出每個腳步,用文字灌溉《海芋小站》,用專業解決問題。

發表迴響