alexjercan/bugnet huggingface dataset:
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
int N;
string S;

string::iterator CountSeqStr(string::iterator start, string *s, int *n) {
  *s = *start;
  *n = 0;
  string tmp;
  for (; tmp = *start, tmp == *s && start != S.end(); ++start) {
    (*n)++;
  }
  return --start;
}

string F() {
  string retS;
  string s;
  string::iterator it;
  int n;
  for (it = S.begin(); it != S.end(); ++it) {
    it = CountSeqStr(it, &s, &n);
    char strn[10000];
    sprintf(strn, "%d", n);
    retS.append(string(strn));
    retS.append(s);
  }
  return retS;
}

int main() {
  while (cin >> N && N) {
    cin >> S;
    for (int i = 0; i < N; i++) {
      string tmp;
      S = F();
    }
    cout << S << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
int N;
string S;

string::iterator CountSeqStr(string::iterator start, string *s, int *n) {
  *s = *start;
  *n = 0;
  string tmp;
  for (; tmp = *start, tmp == *s && start != S.end(); ++start) {
    (*n)++;
  }
  return --start;
}

string F() {
  string retS;
  string s;
  string::iterator it;
  int n;
  for (it = S.begin(); it != S.end(); ++it) {
    it = CountSeqStr(it, &s, &n);
    char *strn;
    sprintf(strn, "%d", n);
    retS.append(string(strn));
    retS.append(s);
  }
  return retS;
}

int main() {
  while (cin >> N && N) {
    cin >> S;
    for (int i = 0; i < N; i++) {
      string tmp;
      S = F();
    }
    cout << S << endl;
  }
  return 0;
}
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: WA

Fixed submission:

#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 = 0;

      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;
}
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#define REP(i, a, n) for (int i = a; i < n; i++)
using namespace std;

int n;
char str[21][100000];

int main(void) {
  while (cin >> n, n != 0) {
    cin >> str[0];

    REP(i, 0, n) {
      int j = 0;
      int k = 0;
      int len = strlen(str[i]);
      while (k < len) {
        int s = k;
        while (k < len && str[i][k] == str[i][k + 1])
          k++;
        int cnt = k - s + 1;
        int l = 0;
        int d[100];
        while (cnt != 0) {
          d[l] = cnt % 10;
          cnt /= 10;
          l++;
        }
        while (l > 0) {
          str[i + 1][j++] = '0' + d[--l];
        }
        str[i + 1][j++] = str[i][s];
        k++;
      }
      str[i + 1][j++] = '\\0';
    }

    cout << str[n] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#define REP(i, a, n) for (int i = a; i < n; i++)
using namespace std;

int n;
char str[21][10000];

int main(void) {
  while (cin >> n, n != 0) {
    cin >> str[0];

    REP(i, 0, n) {
      int j = 0;
      int k = 0;
      int len = strlen(str[i]);
      while (k < len) {
        int s = k;
        while (k < len && str[i][k] == str[i][k + 1])
          k++;
        int cnt = k - s + 1;
        int l = 0;
        int d[100];
        while (cnt != 0) {
          d[l] = cnt % 10;
          cnt /= 10;
          l++;
        }
        while (l > 0) {
          str[i + 1][j++] = '0' + d[--l];
        }
        str[i + 1][j++] = str[i][s];
        k++;
      }
      str[i + 1][j++] = '\\0';
    }

    cout << str[n] << endl;
  }

  return 0;
}
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

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

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

  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;
}
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string.h>

typedef struct {
  char number;
  int num;
} NUMBER;

using namespace std;

NUMBER N[100000];
char str[100000];
char nnn[20];

int main() {
  int n;

  while (scanf("%d", &n), n) {
    strcpy(str, "");
    scanf("%s", str);

    memset(N, 0, sizeof(N));

    for (int c = 0; c < n; c++) {
      int i = 0;
      int j = 0;
      while (str[i] != '\\0') {
        if (i > 0 && str[i] == str[i - 1]) {
          N[j - 1].num++;
        } else {
          N[j].number = str[i];
          N[j].num = 1;
          j++;
        }

        i++;
      }

      strcpy(str, "");

      for (int i = 0; i < j; i++) {
        sprintf(nnn, "%d", N[i].num);
        //				printf("_%s\\n", nnn);

        strcat(str, nnn);
        strncat(str, &N[i].number, 1);
      }
      //			strncat(str, "\\0", 1);
    }

    printf("%s\\n", str);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string.h>

typedef struct {
  char number;
  int num;
} NUMBER;

using namespace std;

NUMBER N[2048];
char str[32768];
char nnn[4096];

int main() {
  int n;

  while (scanf("%d", &n), n) {
    strcpy(str, "");
    scanf("%s", str);

    memset(N, 0, sizeof(N));

    for (int c = 0; c < n; c++) {
      int i = 0;
      int j = 0;
      while (str[i] != '\\0') {
        if (i > 0 && str[i] == str[i - 1]) {
          N[j - 1].num++;
        } else {
          N[j].number = str[i];
          N[j].num = 1;
          j++;
        }

        i++;
      }

      strcpy(str, "");

      for (int i = 0; i < j; i++) {
        sprintf(nnn, "%d", N[i].num);

        strcat(str, nnn);
        strncat(str, &N[i].number, 1);
      }
      //			strncat(str, "\\0", 1);
    }

    printf("%s\\n", str);
  }

  return 0;
}
Problem p00429 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#define INF 100000000
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

static const double eps = 1e-8;

int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;
    string num;
    cin >> num;
    for (int i = 0; i < n; i++) {
      string next;
      for (int j = 0; j < num.size();) {
        int c = 0;
        char alph;
        for (int k = 0; k <= 9; k++) {
          for (int len = 1; j + len - 1 < num.size(); len++) {
            string tmp = num.substr(j, len);
            if (count(tmp.begin(), tmp.end(), '0' + k) == len) {
              c++;
              alph = '0' + k;
            } else
              break;
          }
        }

        j += c;

        char buf[32];
        sprintf(buf, "%d", c);
        string tmp = buf;
        next.append(tmp);
        next.push_back(alph);
      }
      num = next;
    }

    cout << num << endl;
  }
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#define INF 100000000
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

static const double eps = 1e-8;

int main() {
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;
    string num;
    cin >> num;
    for (int i = 0; i < n; i++) {
      string next;
      for (int j = 0; j < num.size();) {
        int c = 0;
        char alph;
        for (int k = 0; k <= 9; k++) {
          for (int len = 1; j + len - 1 < num.size(); len++) {
            string tmp = num.substr(j, len);
            if (count(tmp.begin(), tmp.end(), '0' + k) == len) {
              c++;
              alph = '0' + k;
            }
          }
        }

        j += c;

        char buf[32];
        sprintf(buf, "%d", c);
        string tmp = buf;
        next.append(tmp);
        next.push_back(alph);
      }
      num = next;
    }

    cout << num << endl;
  }
}
Problem p00429 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main(void) {
  int n, l, cnt;
  ostringstream ss;

  while (cin >> n, n) {
    string s[2], prev;
    cin >> s[0];
    int to = 1;
    for (int i = 0; i < n; ++i) {
      l = s[to ^ 1].length();
      s[to] = "";
      int j = 0;
      for (; j < l; ++j) {
        if (j != 0) {
          char c0 = s[to ^ 1].c_str()[j], c1 = prev.c_str()[0];
          if (c0 == c1)
            ++cnt;
          else {
            ss.str("");
            ss.clear(stringstream::goodbit);
            ss << cnt;
            s[to] += ss.str() + prev;
            cnt = 1;
            prev = s[to ^ 1][j];
          }
        } else {
          cnt = 1;
          prev = s[to ^ 1][j];
        }
      }
      ss.str("");
      ss.clear(stringstream::goodbit);
      ss << cnt;
      s[to] += ss.str() + prev;
      to ^= 1;
    }
    cout << s[to ^ 1] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
  int n, i, j, m;
  char s[100000], b;
  stringstream t;
  string u;
  while (cin >> n && n) {
    cin >> s;
    t.str(s);
    u = t.str();
    for (i = 0; i < n; i++) {
      t.str("");
      strcpy(s, u.c_str());
      for (j = 0; j < strlen(s); j++) {
        if (j > 0) {
          if (s[j] == b)
            m++;
          else {
            t << m << b;
            b = s[j];
            m = 1;
          }
        } else {
          b = s[j];
          m = 1;
        }
      }
      t << m << b;
      u += t.str();
    }
    cout << u << endl;
  }
}
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;

int str[21][100000];

int main() {
  int n;
  while (cin >> n, n) {
    int a, r, cntlen;
    char input[101];
    cin >> input;
    for (int i = 0;; i++) {
      if (input[i] == '\\0') {
        str[0][i] = -1;
        break;
      }
      str[0][i] = input[i] - '0';
    }
    for (int i = 0; i < n; i++) {
      /*for(int j=0;str[i][j]!=-1;j++){
          printf("%d",str[i][j]);
      }puts("");*/
      a = -1;
      cntlen = 0;
      for (int j = 0;; j++) {
        if (str[i][j] == -1 || a != str[i][j]) {
          if (~a) {
            str[i + 1][cntlen] = r;
            str[i + 1][cntlen + 1] = a;
            cntlen += 2;
          }
          if (str[i][j] == -1) {
            str[i + 1][cntlen] = -1;
            break;
          }
          a = str[i][j];
          r = 1;
        } else {
          r++;
          if (r == 10) {
            str[i + 1][cntlen] = 1;
            cntlen++;
            r = 0;
          }
        }
      }
    }
    for (int i = 0; str[n][i] != -1; i++) {
      printf("%d", str[n][i]);
    }
    puts("");
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

int str[21][250];

int main() {
  int n;
  while (cin >> n, n) {
    int a, r, cntlen;
    char input[101];
    cin >> input;
    for (int i = 0;; i++) {
      if (input[i] == '\\0') {
        str[0][i] = -1;
        break;
      }
      str[0][i] = input[i] - '0';
    }
    for (int i = 0; i < n; i++) {
      /*for(int j=0;str[i][j]!=-1;j++){
          printf("%d",str[i][j]);
      }puts("");*/
      a = -1;
      cntlen = 0;
      for (int j = 0;; j++) {
        if (str[i][j] == -1 || a != str[i][j]) {
          if (~a) {
            str[i + 1][cntlen] = r;
            str[i + 1][cntlen + 1] = a;
            cntlen += 2;
          }
          if (str[i][j] == -1) {
            str[i + 1][cntlen] = -1;
            break;
          }
          a = str[i][j];
          r = 1;
        } else {
          r++;
          if (r == 10) {
            str[i + 1][cntlen] = 1;
            cntlen++;
            r = 0;
          }
        }
      }
    }
    for (int i = 0; str[n][i] != -1; i++) {
      printf("%d", str[n][i]);
    }
    puts("");
  }
  return 0;
}
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  char ss[100000],
      sst[100000]; // üÍpÆroßpÌ¶ñzñ
  int n, i, j, ki, a, b;

  while (0 <= scanf("%d", &n)) {

    if (n == 0)
      break;
    scanf(" %s ", ss);

    while (n > 0) {
      --n;
      j = 0; // üÍ³ê½¶ñzñÌY
      i = 0; // roßÌ¶ñzñÌY

      // ±Ìfor¶P[vÅÌ©½ÜèPÂð·é
      for (;;) {
        if (ss[j] == '\\0')
          break;
        ki = ss[j];
        b = 1;

        // A±µÄ¢éð¦éiÂÍbÉüêéj
        for (a = j;; a++) {
          if (ss[a] != ss[a + 1])
            break;
          ++b;
        }

        // ªå«¢Ì
        if (b > 99) {
          sst[i] = b / 100 + '0';
          ++i;
        }
        if (b > 9) {
          sst[i] = (b / 10) % 10 + '0';
          ++i;
        }

        sst[i] = b % 10 + '0';
        sst[i + 1] = ki;
        i = i + 2;
        j = a + 1;
        sst[i] = '\\0';
      }

      // roßðüÍpzñÉüêÄ[v
      //			strcpy(ss,sst);
      for (i = 0;; i++) {
        ss[i] = sst[i];
        if (sst[i] == '\\0')
          break;
      }
    }
    printf("%s\\n", sst);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  char ss[10000],
      sst[10000]; // üÍpÆroßpÌ¶ñzñ
  int n, i, j, ki, a, b;

  while (0 <= scanf("%d", &n)) {

    if (n == 0)
      break;
    scanf(" %s ", ss);

    while (n > 0) {
      --n;
      j = 0; // üÍ³ê½¶ñzñÌY
      i = 0; // roßÌ¶ñzñÌY

      // ±Ìfor¶P[vÅÌ©½ÜèPÂð·é
      for (;;) {
        if (ss[j] == '\\0')
          break;
        ki = ss[j];
        b = 1;

        // A±µÄ¢éð¦éiÂÍbÉüêéj
        for (a = j;; a++) {
          if (ss[a] != ss[a + 1])
            break;
          ++b;
        }

        // ªå«¢Ì
        if (b > 99) {
          sst[i] = b / 100 + '0';
          ++i;
        }
        if (b > 9) {
          sst[i] = (b / 10) % 10 + '0';
          ++i;
        }

        sst[i] = b % 10 + '0';
        sst[i + 1] = ki;
        i = i + 2;
        j = a + 1;
        sst[i] = '\\0';
      }

      // roßðüÍpzñÉüêÄ[v
      //			strcpy(ss,sst);
      for (i = 0;; i++) {
        ss[i] = sst[i];
        if (sst[i] == '\\0')
          break;
      }
    }
    printf("%s\\n", sst);
  }

  return 0;
}
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

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

void operate(char str[]);

int main(void) {
  char str[200000];
  int n;

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

    scanf("%s", str);

    while (n) {
      operate(str);
      n--;
    }

    printf("%s\\n", str);
  }
  return (0);
}

void operate(char str[]) {
  char tmp[200000];
  char c;
  int i, j, l, k;
  int tmplen;
  int count;

  memset(tmp, 0, sizeof(tmp));
  l = tmplen = 0;
  while (str[l] != '\\0') {
    c = str[l];
    i = l;
    j = 0;
    while (c == str[i]) {
      j++;
      i++;
    }

    count = 0;
    k = j;
    while (k) {
      count++;
      k /= 10;
    }

    i = count;
    k = j;
    while (count) {
      tmp[tmplen + count - 1] = k % 10 + '0';
      k /= 10;
      count--;
    }
    tmplen += i;
    tmp[tmplen] = c;
    tmplen++;
    l += j;
  }
  strcpy(str, tmp);
}

Error: 0

Fixed submission:

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

void operate(char str[]);

int main(void) {
  char str[10000];
  int n;

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

    scanf("%s", str);

    while (n) {
      operate(str);
      n--;
    }

    printf("%s\\n", str);
  }
  return (0);
}

void operate(char str[]) {
  char tmp[10000];
  char c;
  int i, j, l, k;
  int tmplen;
  int count;

  memset(tmp, 0, sizeof(tmp));
  l = tmplen = 0;
  while (str[l] != '\\0') {
    c = str[l];
    i = l;
    j = 0;
    while (c == str[i]) {
      j++;
      i++;
    }

    count = 0;
    k = j;
    while (k) {
      count++;
      k /= 10;
    }

    i = count;
    k = j;
    while (count) {
      tmp[tmplen + count - 1] = k % 10 + '0';
      k /= 10;
      count--;
    }
    tmplen += i;
    tmp[tmplen] = c;
    tmplen++;
    l += j;
  }
  strcpy(str, tmp);
}
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
int main() {
  int n, turn;
  char str[2][(1 << 20) + 1];

  turn = 0;
  while (std::cin >> n, n) {
    std::cin >> str[turn];
    int len = strlen(str[turn]);

    while (n--) {
      int s = 0;
      for (int i = 0; i < len;) {
        int j;
        char c = str[turn][i];
        for (j = 1, i++; i < len && str[turn][i] == c; i++, j++)
          ;
        // printf("i:%d , j:%d , len:%d , c:%c\\n",i,j,len,c);
        char tmp[101];
        int k = 0;
        while (j > 0) {
          tmp[k++] = (j % 10) + '0';
          j /= 10;
        }
        tmp[k] = 0;
        // printf("___tmp:%s    k:%d\\n",tmp,k);
        while (k > 0) {
          str[turn ^ 1][s++] = tmp[--k];
        }
        str[turn ^ 1][s++] = c;
        // for(int u=0; u<s; u++)printf("%c",str[turn^1][u]);
        // printf("\\n________s_%d______%c\\n",s,str[turn^1][s-1]);
      }
      len = s;
      str[turn ^ 1][len] = 0;
      turn ^= 1;
      // printf("n:%d s:%d __%s\\n\\n",n,len,str[turn]);
    }
    printf("%s\\n", str[turn]);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
int main() {
  int n, turn;
  char str[2][128];

  turn = 0;
  while (std::cin >> n, n) {
    std::cin >> str[turn];
    int len = strlen(str[turn]);

    while (n--) {
      int s = 0;
      for (int i = 0; i < len;) {
        int j;
        char c = str[turn][i];
        for (j = 1, i++; i < len && str[turn][i] == c; i++, j++)
          ;
        // printf("i:%d , j:%d , len:%d , c:%c\\n",i,j,len,c);
        char tmp[101];
        int k = 0;
        while (j > 0) {
          tmp[k++] = (j % 10) + '0';
          j /= 10;
        }
        tmp[k] = 0;
        // printf("___tmp:%s    k:%d\\n",tmp,k);
        while (k > 0) {
          str[turn ^ 1][s++] = tmp[--k];
        }
        str[turn ^ 1][s++] = c;
        // for(int u=0; u<s; u++)printf("%c",str[turn^1][u]);
        // printf("\\n________s_%d______%c\\n",s,str[turn^1][s-1]);
      }
      len = s;
      str[turn ^ 1][len] = 0;
      turn ^= 1;
      // printf("n:%d s:%d __%s\\n\\n",n,len,str[turn]);
    }
    puts(str[turn]);
  }
  return 0;
}
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string.h>

using namespace std;

int main() {
  char in[2][100001], key, temp[100001];
  int n, now, cnt, wrt;
  bool turn;

  while (cin >> n && n) {
    cin >> in[0];
    turn = 1;
    for (int i = 0; i < n; i++) {
      turn = !turn;
      now = 0;
      wrt = 0;
      while (now < strlen(in[turn])) {
        key = in[turn][now];
        cnt = 0;
        while (now < strlen(in[turn]) && key == in[turn][now]) {
          now++;
          cnt++;
        }
        sprintf(temp, "%d", cnt);
        for (int j = 0; j < strlen(temp); j++) {
          in[!turn][wrt] = temp[j];
          wrt++;
        }
        in[!turn][wrt] = key;
        wrt++;
      }
      in[!turn][wrt] = '\\0';
    }
    cout << in[!turn] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string.h>

using namespace std;

int main() {
  char in[2][10001], key, temp[10001];
  int n, now, cnt, wrt;
  bool turn;

  while (cin >> n && n) {
    cin >> in[0];
    turn = 1;
    for (int i = 0; i < n; i++) {
      turn = !turn;
      now = 0;
      wrt = 0;
      while (now < strlen(in[turn])) {
        key = in[turn][now];
        cnt = 0;
        while (now < strlen(in[turn]) && key == in[turn][now]) {
          now++;
          cnt++;
        }
        sprintf(temp, "%d", cnt);
        for (int j = 0; j < strlen(temp); j++) {
          in[!turn][wrt] = temp[j];
          wrt++;
        }
        in[!turn][wrt] = key;
        wrt++;
      }
      in[!turn][wrt] = '\\0';
    }
    cout << in[!turn] << endl;
  }

  return 0;
}