fork(4) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. std::string new_word(std::string & word)
  5. {
  6. using namespace std;
  7.  
  8. string new_word;
  9.  
  10. int pos = 0;
  11. while(pos < word.size())
  12. {
  13. int size = pos;
  14. if(word[pos] != word[size+1])
  15. {
  16. new_word.append(word.begin()+pos,word.begin()+pos+1);
  17. pos++;
  18. continue;
  19. }
  20. else
  21. {
  22. while(word[pos] == word[size+1])
  23. size++;
  24.  
  25. new_word.append(word.begin()+pos,word.begin()+pos+1);
  26. new_word.append(to_string(size-pos+1));
  27.  
  28. pos = size+1;
  29. }
  30. }
  31.  
  32. return new_word;
  33. }
  34.  
  35. int main(int argc, const char * argv[]) {
  36.  
  37. using namespace std;
  38.  
  39. int n;
  40. cin >> n;
  41.  
  42. while(n != 0)
  43. {
  44. string word;
  45. cin >> word;
  46.  
  47. cout << new_word(word) << endl;
  48. n--;
  49. }
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0s 15240KB
stdin
1 TESSSTTNAPIIISS
stdout
TES3T2NAPI3S2