-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution_plain.cc
More file actions
53 lines (45 loc) · 900 Bytes
/
Copy pathsolution_plain.cc
File metadata and controls
53 lines (45 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*************************************************************************
> File Name: solution_plain.cc
> Author: MarkWoo
> Mail:wcgwuxinwei@gmail.com
> Created Time: Tue 03 May 2016 05:44:46 AM PDT
************************************************************************/
#include<iostream>
#include<string>
using namespace std;
class Solution {
public:
void swap(char &pror, char &succ)
{
if (pror != succ)
{
char tmp = pror;
pror = succ;
succ = tmp;
}
}
string reverseString(string s)
{
size_t head = 0;
size_t tail = 0;
if (s.size() != 0)
{
tail = s.size() - 1;
}
for (; head < tail; ++head, --tail)
{
swap(s[head], s[tail]);
}
return s;
}
};
int main(void)
{
string s("hello");
string answer;
Solution solution;
answer = solution.reverseString(s);
std::cout << s << std::endl;
std::cout << answer << std::endl;
return 0;
}