Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- void write_numbers(std::string &s, std::vector<int> &numbers) {
- for(int i = 0; i < (int) s.size(); i++) {
- int j = i, cnt = 0;
- while(j < (int) s.size() and s[i] == s[j]) {
- ++cnt;
- ++j;
- }
- i = j - 1;
- numbers.push_back(cnt);
- }
- }
- void write_characters(std::string &s, std::vector<char> &characters) {
- for(int i = 0; i < (int) s.size(); i++) {
- int j = i;
- char c = s[i];
- while(j < (int) s.size() and s[i] == s[j]) {
- ++j;
- }
- i = j - 1;
- characters.push_back(c);
- }
- }
- void solve() {
- std::string s;
- std::cin >> s;
- try{
- for(int i = 0; i < (int) s.size(); i++) {
- if(s[i] >= 'A' and s[i] <= 'Z') {
- throw "Invalid input!";
- }
- if(s[i] >= '0' and s[i] <= '9') {
- throw "Invalid input!";
- }
- }
- }
- catch(const char *c) {
- std::cout << c << std::endl;
- return;
- }
- std::vector<int> numbers;
- std::vector<char> characters;
- write_numbers(s, numbers);
- write_characters(s, characters);
- for(int i = 0; i < (int) numbers.size(); i++) {
- std::cout << numbers[i] << characters[i];
- }
- std::cout << std::endl;
- }
- int main() {
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement