Advertisement
DiaxPlayer

Untitled

Mar 7th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. string to_string(unsigned int t)
  7. {
  8.     stringstream ss;
  9.     ss << t;
  10.     return ss.str();
  11. }
  12. int main()
  13. {
  14.     int tests;
  15.     cin >> tests;
  16.     for (int i = 0; i < tests; ++i)
  17.     {
  18.         string line;
  19.         string final("");
  20.         getline(cin, line);
  21.         line += '\0';
  22.         char lastChar = '\0';
  23.         char newChar;
  24.         unsigned int charCount = 1;
  25.         for (int j = 0; j < line.size(); i++)
  26.         {
  27.             newChar = line[j];
  28.             if (newChar == lastChar)
  29.             {
  30.                 charCount++;
  31.             }
  32.             else
  33.             {
  34.                 if (charCount == 2)
  35.                 {
  36.                     final += lastChar;
  37.                 }
  38.                 else if (charCount > 2)
  39.                 {
  40.                     final += to_string(charCount);
  41.                 }
  42.                 lastChar = newChar;
  43.                 charCount = 1u;
  44.                 if (newChar != '\0')
  45.                 {
  46.                     final += newChar;
  47.                 }
  48.             }
  49.         }
  50.         cout << final << endl;
  51.     }
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement