-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstReverse.cpp
More file actions
51 lines (32 loc) · 950 Bytes
/
FirstReverse.cpp
File metadata and controls
51 lines (32 loc) · 950 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
// FirstReverse.cpp
// 20210317
// arataca89@gmail.com
// Aulas particulares de programação C++
// Coderbyte exercise:
// Have the function FirstReverse(str) take the str parameter being
// passed and return the string in reversed order.
// For example: if the input string is "Hello World and Coders" then
// your program should return the string "sredoC dna dlroW olleH".
#include <iostream>
using std::cout;
using std::endl;
#include <string>
using std::string;
string FirstReverse(string str) {
int size = str.length();
string buffer = str;
int i,j=0;
for(i=size-1;i>=0;i--)
buffer[j++] = str[i];
buffer[j]='\0';
for(i=0;i<size;i++)
str[i] = buffer[i];
return str;
}
int main(){
string s = "string";
cout << "string original : " << s << endl;
cout << "apos chamada a FirstReverse(): " << FirstReverse(s) << endl;
return 0;
}
// end of FirstReverse.cpp