Skip to content

Commit

Permalink
[cpp] Challenge 1 (Unreviewed)
Browse files Browse the repository at this point in the history
  • Loading branch information
dewie102 committed Jan 21, 2017
1 parent 45311a3 commit 0957a7b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
19 changes: 19 additions & 0 deletions challenge_1/cpp/dewie102/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Reverse a String
###### C++ 11

### 1. Approch to solving the problem

Iterate through the string to be reveresed starting from the end and add each those letter to another string that is output.

### 2. How to compile and run this

In Windows - I used the Visual Studio C++ compiler, move to the proper directory and run:

```
cl.exe /EHsc src/ReverseString.cpp
ReverseString.exe
```

### 3. How this program works

I take an input string and iterate through it backwards taking each letter and adding it to the back of the output string.
24 changes: 24 additions & 0 deletions challenge_1/cpp/dewie102/src/ReverseString.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
#include <string>

using namespace std;

string ReverseString(string input) {
string output;
for(int i = input.length() - 1; i >= 0; --i) {
output.push_back(input[i]);
}

return output;
}

int main(int argc, char** argv) {
string input;
string output;

cout << "Please enter a string you wish to reverse: ";
getline(cin, input);
output = ReverseString(input);
cout << "The reversed string is: " << output << endl;
return 0;
}

0 comments on commit 0957a7b

Please sign in to comment.