Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
38 changes: 38 additions & 0 deletions answers/q1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//1. Print Hello world! in reverse

#include <iostream>

using namespace std;

string wordReverse(string str)
{
int i = str.length() - 1;
int start, end = i + 1;
string result = "";

while (i >= 0) {
if (str[i] == ' ') {
start = i + 1;
while (start != end)
result += str[start++];

result += ' ';

end = i;
}
i--;
}
start = 0;
while (start != end)
result += str[start++];

return result;
}
int main()
{
string str = "Hello World";

cout << wordReverse(str);

return 0;
}
Empty file added answers/q2.cpp
Empty file.