[請益] 求幫忙C++程式(初學者)

作者: Struggling (Struggling)   2016-11-01 00:04:47
本魯非CS背景,請求幫忙解題
作業有AB題,我做了A題OK,B題是逆向,寫不出來QQ
A題簡介
輸入1234,電腦輸出1423
B題簡介
輸入1423,電腦輸出1234
以下是我A題的code
#include <iostream>
#include <string>
using namespace std;
void mash(string s);
int main()
{
string s;
cout << "Enter a sequence: ";
getline(cin, s);
mash(s);
cout << endl;
}
void mash(string s)
{
int a =s.length();
if (a == 0)
{
return;
}
cout << s[0];
if(a>1)
cout<< s[a-1];
s.erase(0, 1);
a = s.length();
if(a>=1)
s.erase(a-1);
mash(s);
}

Links booklink

Contact Us: admin [ a t ] ucptt.com