Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cpp] Challenge 1 (Unreviewed) #446

Merged
merged 7 commits into from
Jan 23, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[cpp] Challenge 1 (Unreviewed)
  • Loading branch information
dewie102 committed Jan 21, 2017
commit 0957a7bcdc00d11c072d2a657ae885a9429ef9f0
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;
}