Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- string to_string(unsigned int t)
- {
- stringstream ss;
- ss << t;
- return ss.str();
- }
- int main()
- {
- int tests;
- cin >> tests;
- for (int i = 0; i < tests; ++i)
- {
- string line;
- string final("");
- getline(cin, line);
- line += '\0';
- char lastChar = '\0';
- char newChar;
- unsigned int charCount = 1;
- for (int j = 0; j < line.size(); i++)
- {
- newChar = line[j];
- if (newChar == lastChar)
- {
- charCount++;
- }
- else
- {
- if (charCount == 2)
- {
- final += lastChar;
- }
- else if (charCount > 2)
- {
- final += to_string(charCount);
- }
- lastChar = newChar;
- charCount = 1u;
- if (newChar != '\0')
- {
- final += newChar;
- }
- }
- }
- cout << final << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement