Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <list>
- #include <algorithm>
- #include <string>
- using namespace std;
- void reverse_string(string);
- int main() {
- string str;
- int character = (int)calloc(4, sizeof(int));
- int i = (int)calloc(256, sizeof(int));
- for(character = getchar(); character != '.'; character = getchar(), i++)
- str += character;
- reverse_string(str);
- return 0;
- }
- void reverse_string(string str) {
- list<char> linked_list;
- reverse(str.begin(), str.end());
- for(size_t i = 0; i < str.length(); i++) {
- if(str[i] != ' ') {
- linked_list.push_back(str[i]);
- } else {
- while(!linked_list.empty()) {
- printf("%c", linked_list.back());
- linked_list.pop_back();
- }
- printf(" ");
- }
- }
- while(!linked_list.empty()) {
- printf("%c", linked_list.back());
- linked_list.pop_back();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement