Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #include <string>
- #include <algorithm>
- enum { MAX_SIZE = 32768 };
- // bool comp(char *p1, char *p2)
- // {
- // return std::strcmp(p1, p2) < 0;
- // }
- int main()
- {
- char s[MAX_SIZE], c;
- int i = 0, size;
- while ((std::cin.get(c)) && !std::cin.eof()) {
- s[i++] = c;
- }
- //truncatig
- size = std::strlen(s); // will be actual size of truncated string
- for (int i = size - 1; i >= 0; --i) {
- if (s[i] == ' ') {
- size--;
- } else {
- break;
- }
- }
- char *ptrs[size];
- for (int i = 0; i < size; ++i) {
- ptrs[i] = s + sizeof(int) * i;
- }
- for(int i = 0; i < size; ++i) {
- std::cout<<ptrs[i]<<std::endl;
- }
- std::sort(ptrs, ptrs+size, [](char *p1, char *p2) {
- return (std::strcmp(p1, p2)) < 0;
- });
- for (int i = 0; i < size; ++i) {
- std::cout << (ptrs[i] - s)/sizeof(int) << std::endl;
- }
- // for(int i = 0; i < size; ++i) {
- // std::cout<<ptrs[i]<<std::endl;
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement