Problem:
0 から 9 までの数字だけで構成された文字列が与えられたとき,その文字列から次の規則に従って新しい文字列を作る操作を考える.与えられた文字列を左端から1文字ずつ順に読んで行き,同じ数字
a
が
r
個続いていた場合,個数
r
と数字
a
を空白で区切らずにこの順で書き出す.与えられた文字列の右端まで読み,最後の書き出しが終わったところまでを途中何回書き出しがあったとしても全部まとめて操作1回とカウントする.2回目以降の操作は前回の操作により書き出された文字列を与えられた文字列として同様の操作を実施する.例えば “
122244
” という文字列が与えられた場合には左端から順に1個の1, 3個の2,2個の4なのでこの操作1回で得られる文字列は “
113224
” であり,“
44444444444
” (11 個の4)の場合には得られる文字列は “
114
” となる.
100 文字以下の与えられた文字列に上の操作を
n
回実施した文字列を出力するプログラムを作成せよ.ただし,
n
≤ 20 とする.
入力データ は 2 行からなり,1 行目に操作回数
n
, 2 行目に最初の文字列が書かれている.
入力例
5
11
出力例
13112221
入力
入力は複数のデータセットからなる．n が 0 のとき入力が終了する．データセットの数は 5 を超えない．
出力
データセットごとに、指定された回数の操作を施した文字列 を１行に出力する．
入力例
5
11
5
11
0
出力例
13112221
13112221
上記問題文と自動審判に使われるデータは、
情報オリンピック日本委員会
が作成し公開している問題文と採点用テストデータです。

Submitted solutions:

code_snippet: #include <iostream>
#include<string>
using namespace std;

int main() {
    int n ;
    string str;

    while (true) {
        cin >> n;

        if (n == 0) {
            break;
        }
        str = "";
        cin >> str;

        int cnt;
        string resultStr;
        // n回ループ
        for (int i=0; i<n; i++) {
            cnt = 1;
            resultStr = "";
            str.push_back('e');

            char crtCh, nxtCh;
            // 文字列数 - 1 回ループ
            for (int j=0; j<str.size()-1; j++) {
                crtCh = str[j];
                nxtCh = str[j+1];

                if (crtCh == nxtCh) {
                    cnt += 1;
                } else {
                    resultStr.append(to_string(cnt));
                    resultStr.append(to_string(static_cast<int>(crtCh-'0')));
                    cnt = 1;
                }
            }

            str = "";
            str.assign(resultStr);
            resultStr = "";

        }

        cout << str << endl;
    }
    
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3284
final_rank: 4

code_snippet: #include <bits/stdc++.h>

int main()
{
    std::string str, tmp;
    char c;
    int N, cnt;

    while(1) {
        std::cin >> N;
        if (N == 0) break;
        std::cin >> str;
        for (int i = 0; i < N; i++) {
            c = str[0]; cnt = 1; tmp = "";
            for (unsigned long j = 1; j < str.size(); j++) {
                if (str[j] == c) {
                    cnt++;
                    continue;
                } else {
                    tmp += std::to_string(cnt) + c;
                    cnt = 1;
                    c = str[j];
                }
            }
            tmp += std::to_string(cnt) + c;
            str = tmp;
        }
        std::cout << str << std::endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3400
final_rank: 10

code_snippet: #include <iostream>
#include <queue>
#include <string>
#include <utility>

using namespace std;

int main()
{
  int n;
  string str;
  queue<pair<int, int> > q;
  pair<int, int> p;

  while (1) {
    cin >> n;
    if (n == 0) break;
    cin.ignore();
    cin >> str;
    int run = 1;
    while (n--) {
      str += "-";
      while (!q.empty()) q.pop();
      for (int i = 0; i < str.size() - 1; i++) {
        if (str[i] == str[i + 1]) {
          run++;
        } else {
          p.first = run;
          p.second = str[i] - '0';
          q.push(p);
          run = 1;
        }
      }
      str.clear();
      while (!q.empty()) {
        str += to_string(q.front().first) + to_string(q.front().second);
        q.pop();
      }
    }
    cout << str << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3416
final_rank: 11

code_snippet: #include<iostream>
#include<string>
#include<vector>
#include<sstream>
using namespace std;
template < typename T > string to_string( const T& n ){
    {
        ostringstream oss ;
        oss << n ;
        return oss.str() ;
    }
}
int main(){
    int n;
    vector<string> a(5);
    for(int i = 0; i < 5;i++){
        a[i] = "";
    }
    int k = 0;
    while(1){
        cin >> n;
        if(n == 0)break;
        string s;
        string f = "";
        cin >> s;
        for(int i = 0;i < n;i++){
            int size = s.size();
            //cout << s << " *" <<endl;
            for(int j = 0;j < size;j++){
                int l = 1;
                while(1){
                    if(s[j] == s[j+l] && j + l < size){
                        l++;
                    }
                    else {
                        j += l - 1;
                        string b = to_string(l);
                        f += b;
                        f += s[j];
                        
                        break;
                    }
                }
            }
            s = f;
            //cout << k << " " << i << " " << s << endl; 
            f = "";
        }
        a[k] = s;
        k++;
    }
    for(int i = 0;i < k;i++){
        cout << a[i] << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3280
final_rank: 15

code_snippet: #include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
// #include <boost/foreach.hpp>
// #include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
//#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};
//typedef pair<int,int> P;

const long long MOD=1000000007LL;
bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)||islower(c));}
template<typename T> 
void print(vector<T> v){
    for(int i=0;i<v.size();i++){
        if(i)cout<<" ";
        cout<<v[i];
    }
    cout<<endl;
}
int INF=1e18;

template<typename T>
void printendl(vector<T> v){
    for(auto date:v)cout<<date<<endl;
}

template<typename T>
void printvv(vector<vector<T>> v){
    for(int i=0;i<v.size();i++){
        for(int j=0;j<v[i].size();j++){
            if(j)cout<<" ";
            cout<<v[i][j];
        }
        cout<<endl;
    }
}
int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    else return gcd(b,a%b);
}

struct Edge{
    int to,cost;
};
struct S{
    int n;
    char c;
};

string f(string s){
    vector<S> v;
    rep(i,0,s.size()){
        int num=1;
        while(i+1<s.size() && s[i]==s[i+1]){
            i++;
            num++;
        }
        v.push_back(S{num,s[i]});
    }

    string ret;
    for(int i=0;i<v.size();i++){
        ret+=to_string(v[i].n)+v[i].c;
    }
    return ret;
}

signed main (){
    int n;
    while(cin>>n){
        if(n==0)break;
        string s;
        cin>>s;
        rep(i,0,n){
            s=f(s);
        }
        cout<<s<<endl;
    }


    

    
    
}
/*

*/
accuracy: 1
time_ms: 10
memory_kb: 3928
final_rank: 17

code_snippet: #include <cstdio>
#include <cctype>
#include <utility>
#include <string>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	string s, b;
	for (int n; (n = in());) {
		scan(s);
		while (n--) {
			b = "";
			char p = ' ';
			int q = 0;
			for (char c: s) {
				if (c == p)
					q++;
				else {
					if (q)
						b += to_string(q) + p;
					q = 1;
					p = c;
				}
			}
			if (q)
				b += to_string(q) + p;
			s = b;
		}
		outl(s);
	}
}
accuracy: 1
time_ms: 10
memory_kb: 2688
final_rank: 1

code_snippet: #include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	while(true){
	int n;
	cin >> n;
	if(n == 0) return 0;
	string S;
	cin >> S;
	for(int q=0; q<n; q++){
		string next = "";
		int now = 0;
		char l = '-';
		for(int i=0; i<S.size(); i++){
			if(S[i] != l){
				if(now > 0) next+= to_string(now) + l;
				l = S[i];
				now = 0;
			}
			now++;
		}
		if(now > 0) next+= to_string(now) + l;
		S = next;
	}
	cout << S << endl;
	}

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3336
final_rank: 8

code_snippet: #include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string operation(string s){
	string ret = "";
	int it = 0;
	while(it < s.size()){
		int cnt = 1;
		while(it < s.size()-1 && s[it] == s[it+1]){
			cnt++;
			it++;
		}
		ret += to_string(cnt) + s[it];
		it++;
	}
	return ret;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	while(true){
		int n; cin >> n;
		if(n==0) break;
	 	string s; cin >> s;

		for (int i = 0;i < n;i++){
			s = operation(s);
		}

		cout << s << endl;
	}

	return 0;

}
accuracy: 1
time_ms: 10
memory_kb: 3332
final_rank: 7

code_snippet: #include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main() {
    while (1) {
        int n;
        scanf("%d", &n);
        if (n == 0) {
            break;
        }

        string now, tmp;
        cin >> now;
        int size;
        int cnt = 0;
        char before = ' ';
        for (int i = 0; i< n; i++) {
            tmp = now;
            size = tmp.size();
            for (int j = 0; j < size; j++) {
                if (j == 0) {
                    now = "";
                    cnt = 1;
                } else {
                    if (before == tmp[j]) {
                        cnt++;
                    } else {
                        now += to_string(cnt) + before;
                        cnt = 1;
                    }
                }
                
                before = tmp[j];
                if (j == size-1) {
                    now += to_string(cnt) + before;
                }
            }
        }
        cout << now << "\n";
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3464
final_rank: 14

code_snippet: #include <iostream>
#include <string>
using namespace std;

int main(){
    string in;
    int n;
    while(cin >> n >> in){
        if(n == 0) break;
        string nstr = "";
        int count = 1;
        for(int j = 0;j<n;j++){
            nstr = "";
            count = 1;
        for(int i = 1;i<in.length();i++){
            if(in[i-1] != in[i]){
                nstr += to_string(count) + in[i-1];
                count = 1;
            }
            else{
                count++;
            }
            // cout << nstr << endl;
        }
        nstr += to_string(count) + in[in.length()-1];
        in = nstr;
        }
        cout << in << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3260
final_rank: 3

code_snippet: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

/*
<url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0506>
?????????============================================================
0 ?????? 9 ?????§?????°???????????§?§??????????????????????????????????????????¨???,
??????????????????????¬??????????????????£?????°??????????????????????????????????????????.
???????????????????????????????????????1??????????????????????????§??????,????????°??? a ??? r ????¶???????????????´???,
?????° r ??¨??°???a ???????????§??????????????????????????§????????????.??????????????????????????????????????§??????,
????????????????????????????????£?????¨???????????§???????????????????????????????????£?????¨???????????¨??¨?????¨??????
??????1?????¨??????????????????.2????????\????????????????????????????????????????????????????????????????????????????????????
???????????¨??????????§?????????????????????????.????????° ???122244??? ??¨???????????????????????????????????´?????????
??????????????????1??????1, 3??????2,2??????4????????§????????????1?????§???????????????????????? ???113224??? ??§??????
,???44444444444??? (11 ??????4)?????´????????????????????????????????? ???114??? ??¨??????.

100 ????????\???????????????????????????????????????????????? n ???????????????????????????????????????????????°?????????????????????.
?????????, n ??? 20 ??¨??????.
=================================================================
??\???=============================================================
??\???????????°????????????????????????????????????n ??? 0 ?????¨?????\????????????????????????????????????????????°??? 5 ????¶?????????????
================================================================
??????=============================================================
???????????????????????¨??????????????????????????°?????????????????????????????? ???????????????????????????
================================================================
?§£??¬=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll n;
	while (cin >> n, n) {
		string s; cin >> s;
		for (int i = 0; i < n;i++) {
			char c;
			int cnt;
			string next;
			for (int j = 0; j <= s.length(); j++) {
				if (j == s.length()) {
					next += to_string(cnt) + c;
				}
				else {
					if (j == 0) {
						c = s[j]; cnt = 1;
						continue;
					}
					else {
						if (c == s[j])cnt++;
						else {
							next += to_string(cnt) + c;
							c = s[j];
							cnt = 1;
						}
					}
				}
			}
			s = next;
		}
		cout << s << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3344
final_rank: 9

code_snippet: #include <iostream>
#include <sstream>

int main() {
    int n;
    while (std::cin >> n && n) {
        std::string s1, s2;
        std::cin >> s1;

        for (int i = 0; i < n; i++) {
            s1 += 'a';
            s2 = "";
            char pre = s1[0];
            s1.erase(s1.begin(), s1.begin() + 1);
            int count = 1;
            for (char cur : s1) {
                if (pre == cur) {
                    count++;
                } else {
                    std::stringstream ss("");
                    ss << count, s2 += ss.str() + pre;
                    pre = cur, count = 1;
                }
            }
            s1 = s2;
        }
        std::cout << s1 << std::endl;
    }
}
accuracy: 1
time_ms: 40
memory_kb: 3104
final_rank: 13

code_snippet: #include <string>
#include <iostream>
using namespace std;

string change(string s) {
	string res = "";
	char c = s.front();
	int count = 1;
	for (auto i = s.begin()+1;i != s.end();++i) {
		if (*i == c) {
			++count;
		} else {
			res += to_string(count) + c;
			c = *i;
			count = 1;
		}
	}
	res += to_string(count) + c;
	return res;
}

int main() {
	while (true) {
		int n;
		cin >> n;
		cin.ignore();
		if (n == 0) {
			break;
		}
		string s;
		cin >> s;
		while (n--) {
			s = change(s);
		}
		cout << s << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3224
final_rank: 2

code_snippet: #include <stdio.h>
#include <string.h>

char str[100000];
char ans[100000];

void sort();
int main(){
  int n;
  while (1){
    scanf("%d", &n);
    if (n == 0){ break; }
    scanf("%s", str);
    while( n>0 ){
      sort();
      memcpy(str, ans, sizeof(ans));
      n--;
    }
    printf("%s\n", ans);
  }
  return 0;
}
void sort(){

  int	i, j, len;
  char	countbuf[10], valuebuf[10];
  int	count;

  len = strlen(str);
  memset(ans, '\0', sizeof(ans));
  for (i = 0; i < len; i++){
    if (str[i-1] != str[i]){
      count = 0;
      for (j = i; j < len; j++){
	if (str[i] == str[j]){
	  count++;
	}
	else{ break; }
      }
      memset(valuebuf, '\0', sizeof(valuebuf));
      sprintf(countbuf, "%d", count);
      valuebuf[0] = str[i];
      strcat(ans, countbuf);
      strcat(ans, valuebuf);
      memset(countbuf, '\0', sizeof(countbuf));
    }
  }
}
accuracy: 1
time_ms: 110
memory_kb: 2768
final_rank: 16

code_snippet: #include <stdio.h>
#include <string.h>

char str[100000];
char ans[100000];

void sort();

int main(){

  int n;
  while (1){
    scanf("%d", &n);
    if (n == 0){ break; }
    scanf("%s", str);
    while( n>0 ){
      sort();
      memcpy(str, ans, sizeof(ans));
      n--;
    }
    printf("%s\n", ans);
  }

  return 0;
}
void sort(){

  int	i, j, len;
  char	c = '\0';
  char	countbuf[10], valuebuf[10];
  int	count;

  len = strlen(str);
  memset(ans, '\0', sizeof(ans));
  for (i = 0; i < len; i++){
    if (c != str[i]){
      count = 0;
      for (j = i; j < len; j++){
	if (str[i] == str[j]){
	  count++;
	}
	else{ break; }
      }
      memset(valuebuf, '\0', sizeof(valuebuf));
      sprintf(countbuf, "%d", count);
      valuebuf[0] = str[i];
      strcat(ans, countbuf);
      strcat(ans, valuebuf);
      memset(countbuf, '\0', sizeof(countbuf));
      c = str[i];
    }
  }
}
accuracy: 1
time_ms: 110
memory_kb: 2824
final_rank: 19

code_snippet: #include <stdio.h>
#include <string.h>

int main()
{
  int	n;
  char	str[100000];
  char	tmp[100000];

  while(1){
    scanf("%d",&n);
    if (n == 0){ break; }
    scanf("%s",str);
 	
    while( n>0 ){
      int	i,j,len;

      len = strlen(str);
      memset(tmp, '\0', sizeof(tmp));
      char	c = '\0';
      char	countbuf[10],valuebuf[10];
      int	count;

      for(i = 0;i < len;i++){
	if (c != str[i]){
	  count = 0;
	  for (j = i; j < len; j++){
	    if( str[i]==str[j]){
	      count++;
	    }else{
	      break;
	    }    
	  }
	  memset(valuebuf,'\0',sizeof(valuebuf));
	  valuebuf[0] = str[i];
	  sprintf(countbuf,"%d", count);
	  strcat(tmp,countbuf);
	  strcat(tmp,valuebuf);
	  memset(countbuf, '\0', sizeof(countbuf));
	  c = str[i];
	}
      }
      memcpy(str,tmp,sizeof(tmp));   
      n--;
    }
  
    printf("%s\n", tmp);	
  }
  return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 2812
final_rank: 18

code_snippet: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n;
	while (cin >> n, n) {
		string s; cin >> s;
		while (n--) {
			string t;
			int i(0);
			while (i < s.length()) {
				int x(1);
				for (int j = i + 1; j < s.length() && s[i] == s[j]; j++) {
					x++;
				}
				t += to_string(x) + s[i];
				i += x;
			}
			s = t;
		}
		cout << s << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3324
final_rank: 5

code_snippet: #include <stdio.h>
#include <string.h>

int main()
{
  int	n;
  char	str[100000];
  char	tmp[100000];

  while(1){
    scanf("%d",&n);
    if (n == 0){ break; }
    scanf("%s",str);
 	
    while( n>0 ){
      int i,j,len;

      len = strlen(str);
      memset(tmp, '\0', sizeof(tmp));
      char c = '\0';
      char	countbuf[10],valuebuf[10];
      int count;

      for(i = 0;i < len;i++){
	if (c != str[i]){
	  count = 0;
	  for (j = i; j < len; j++){
	    if( str[i]==str[j]){
	      count++;
	    }else{
	      break;
	    }    
	  }
	  memset(valuebuf,'\0',sizeof(valuebuf));
	  valuebuf[0] = str[i];
	  sprintf(countbuf,"%d", count);
	  strcat(tmp,countbuf);
	  strcat(tmp,valuebuf);
	  memset(countbuf, '\0', sizeof(countbuf));
	  c = str[i];
	}
      }
      memcpy(str,tmp,sizeof(tmp));   
      n--;
    }
  
    printf("%s\n", tmp);	
  }
  return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 2864
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0;i < N;i++)

string to_str(int n){
  ostringstream os;
  os << n;
  return os.str();
}

int main()
{
  int N;
  string s;
  while(cin >> N,N) {
    cin >> s;
    while(N--) {
      string w;
      int np = 0;
      while(np < s.size()){
	char c = s[np];
	int i = 1;
	for(np = np + 1;s[np] == c && np < s.size();np++,i++);
	w += to_str(i);
	w += c;
      }
      s = w;
    }
    cout << s << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3204
final_rank: 12

code_snippet: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
	int N,cnt;
	string str,str2;
	char ch;
	while(true){
		cin>>N;
		if(N==0) break;
		cin>>str;
		for(int i=0;i<N;i++){
			cnt=1;
			str2="";
			for(int j=0;j<str.size()-1;j++){
				if(str[j]!=str[j+1]){
					str2+=(to_string(cnt)+str[j]);
					cnt=1;
				}
				else cnt++;
			}
			str2+=(to_string(cnt)+str[str.size()-1]);
			swap(str,str2);
		}
		cout<<str<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3328
final_rank: 6