Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- class Token {
- public:
- int occurences;
- char value;
- private:
- };
- void check_validity(string user_input) {
- for (int c : user_input) {
- if (c < 'a' || c > 'z') throw runtime_error("invalid input");
- }
- }
- int main() {
- try {
- string input;
- vector<Token> results = {};
- int count = 1;
- cin >> input;
- check_validity(input);
- for (int i = 0; i < input.size() - 1; i++) {
- if (input[i] == input[i++]) {
- count++;
- }
- else {
- Token t;
- t.occurences = count;
- t.value = input[i];
- results.push_back(t);
- }
- }
- cout << count;
- for (Token t : results) {
- cout << t.occurences << t.value;
- }
- cout << endl;
- }
- catch (runtime_error& e) {
- cerr << "error: " << e.what() << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement