Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "boost/scoped_array.hpp"
- #include "boost/scoped_ptr.hpp"
- #include "boost/shared_ptr.hpp"
- #include "boost/weak_ptr.hpp"
- #include "boost/make_shared.hpp"
- #include "boost/smart_ptr/enable_shared_from_this.hpp"
- #include "boost/lexical_cast.hpp"
- #include "boost/optional.hpp"
- #include "boost/none.hpp"
- #include <map>
- #include <algorithm>
- #include <vector>
- #include <sstream>
- #include <iomanip>
- #include <string>
- #include <list>
- #include <bitset>
- #include <thread>
- #include <utility>
- #include <initializer_list>
- #include <memory>
- #include <netinet/in.h>
- #include <functional>
- #include <chrono>
- #include <cstring>
- #include <ctime>
- #include <set>
- #include <memory>
- #include <iostream>
- #include <atomic>
- #include <thread>
- #include <mutex>
- #include <iostream>
- #include <chrono>
- #include <thread>
- #include <chrono>
- #include <map>
- #include <tuple>
- #include <utility>
- #include <set>
- #include <initializer_list>
- #include <algorithm>
- #include <vector>
- #include <string>
- #include <chrono>
- using namespace std;
- std::string evaulateString(std::string str)
- {
- std::string evaulatedStr;
- for (auto i = size_t{0}; i < str.size();)
- {
- auto currentChar = str.at(i);
- auto currentCounter = int {0};
- while (str.at(i) == currentChar)
- {
- ++currentCounter;
- ++i;
- if (i == (str.size()))
- {
- break;
- }
- }
- if (currentCounter)
- {
- evaulatedStr += static_cast<char>(currentCounter+48);
- }
- evaulatedStr += currentChar;
- }
- return evaulatedStr;
- }
- int elvesLookElvesSay(std::string str, int iteration = 0)
- {
- if (iteration == 40)
- {
- return str.size();
- }
- else
- {
- return elvesLookElvesSay(std::move(evaulateString(str)), ++iteration);
- }
- }
- int main()
- {
- for (auto i = 0; i < 100; ++i)
- {
- std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
- auto res = elvesLookElvesSay("1321131112");
- std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
- cout << res << " and it took: " << " (" << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << " ms)" << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment