alexjercan/bugnet huggingface dataset:
Problem p00429 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
int n;
char c[50000], d[50000], f[10];
int main() {
  while (scanf("%d", &n), n) {
    scanf("%s", c);
    for (int i = 0; i < n; i++) {
      int l = strlen(c), m = 0, e = 0;
      for (int j = 1; j <= l; j++) {
        if (c[j - 1] != c[j]) {
          sprintf(f, "%d%c", j - e, c[j - 1]);
          int l2 = strlen(f);
          e = j;
          for (int k = 0; k < l2; k++)
            d[m++] = f[k];
          d[m] = 0;
        }
      }
      strcpy(c, d);
    }
    printf("%s\\n", c);
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

string operation(string S) {
  string T;

  int left = 0;

  if (S.size() == 1) {
    return "1" + S;
  }

  for (int i = 1; i < S.size(); i++) {
    if (S[i - 1] != S[i]) {
      T += (to_string(i - left) + S[i - 1]);

      left = i;
    }

    if (i + 1 == S.size()) {
      T += (to_string(S.size() - left) + S[i]);
    }
  }

  return T;
}

int main() {
  int n;
  string S;

  while (true) {
    cin >> n;

    if (n == 0) {
      break;
    }

    cin >> S;

    for (int i = 0; i < n * 2; i++) {
      S = operation(S);
    }

    cout << S << endl;
  }

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

#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define PI 3.14159265359

#define INF 99999999;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)

typedef long long ll;

using namespace std;

/*
class TheKingsArmyDiv2
{
public:
        int getNumber(vector <string> state)
        {

        }
};
*/

int main() {
  int N;

  while (cin >> N, N) {
    string str;
    char c;
    int co;

    cin >> str;
    while (N > 0) {
      N--;
      string t;
      co = 1;
      c = str[0];
      for (int i = 1; i < str.size(); i++) {
        if (str[i] == c) {
          co++;
        } else {
          char s[10];
          sprintf(s, "%d", co);
          t += s;
          t.push_back(c);

          c = str[i];
          co = 1;
        }
      }
      char s[10];
      sprintf(s, "%d", co);
      t += s;
      t.push_back(c);
      str = t;
    }
    cout << str.c_str() << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
// #include <map>
#include <vector>

using namespace std;

string get_new_string(string old) {
  int cnt = 1;
  string ret;
  stringstream ss;

  if (old == "")
    return "";

  while (old[cnt] == old[0]) {
    cnt++;
  }

  // cout << "cnt = " << cnt << endl;

  ss << cnt << old[0];

  return ss.str() + get_new_string(old.substr(cnt));
}

int main() {
  string str;
  int n;

  while (cin >> n >> str) {
    for (int i = 0; i < n; i++) {
      str = get_new_string(str);
    }

    cout << str << endl;
  }

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

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

int main() {
  int n;
  string s;
  while (cin >> n && n != 0) {
    cin >> s;
    for (int i = 0; i < n; i++) {
      int x = 0;
      char ch = s[0];
      string tmp = "";
      for (int j = 0; j < s.length(); j++) {
        if (ch == s[j]) {
          x++;
        } else {
          stringstream ss;
          ss << x;
          string cnt = ss.str();
          tmp += cnt;
          tmp.push_back(ch);
          ch = s[j];
          x = 1;
        }
      }
      stringstream ss;
      ss << x;
      string cnt = ss.str();
      tmp += cnt;
      tmp.push_back(ch);
      s = tmp;
    }
    cout << s << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;

int main() {
  int n, m, num;
  while (scanf("%d %d", &n, &m) && n != 0 && m != 0) {
    pair<int, int> place[m];
    for (int i = 0; i < m; i++) {
      place[i].first = 0;
      place[i].second = i + 1;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        scanf("%d", &num);
        if (num == 1)
          place[j].first++;
      }
    }
    for (int i = 0; i < m - 1; i++) {
      for (int j = m - 1; j > i; j--) {
        if (place[j].first > place[j - 1].first) {
          swap(place[j], place[j - 1]);
        }
      }
    }
    for (int i = 0; i < m; i++) {
      if (i != 0)
        printf(" ");
      printf("%d", place[i].second);
    }
    printf("\\n");
  }
}
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  while (scanf("%d", &n) && n) {
    string a;
    cin >> a;
    for (int i = 0; i < n; i++) {
      string b;
      int ro = 1;
      for (int i = 1; i < a.size(); i++) {
        if (a[i - 1] == a[i]) {
          ro++;
        } else {
          string ru;
          while (ro) {
            int r = ro % 10;
            ru.push_back(r + '0');
            ro /= 10;
          }
          ro = 1;
          reverse(ru.begin(), ru.end());
          b += ru;
          b.push_back(a[i - 1]);
        }
      }
      string ru;
      while (ro) {
        int r = ro % 10;
        ru.push_back(r + '0');
        ro /= 10;
      }
      ro = 1;
      reverse(ru.begin(), ru.end());
      b += ru;
      b.push_back(a[a.size() - 1]);
      a = b;
    }
    cout << a << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
  while (1) {
    char str[10000], strcopy[10000];
    int a, b = 0, c, d, e, f, g, h, i, j, k, l, n, x, y, z, sum = 1, leng;
    scanf("%d", &a);
    if (a == 0)
      break;
    scanf("%s", &str);
    leng = strlen(str);
    for (j = 0; j < a; j++) {
      for (i = 1; i < strlen(str); i++) {
        if (str[i - 1] == str[i]) {
          sum++;
        } else {
          if (sum >= 10) {
            strcopy[b] = sum / 10 + '0';
            strcopy[b + 1] = sum % 10 + '0';
            strcopy[b + 2] = str[i - 1];
            b += 3;
            sum = 1;
          } else {
            strcopy[b] = sum + '0';
            strcopy[b + 1] = str[i - 1];
            b += 2;
            sum = 1;
          }
        }
      }
      if (sum >= 10) {
        strcopy[b] = sum / 10 + '0';
        strcopy[b + 1] = sum % 10 + '0';
        strcopy[b + 2] = str[strlen(str) - 1];
        b += 3;
        sum = 1;
      } else {
        strcopy[b] = sum + '0';
        strcopy[b + 1] = str[strlen(str) - 1];
        b += 2;
        sum = 1;
      }
      leng = strlen(strcopy);
      strcpy(str, "");
      for (i = 0; i < leng; i++) {
        str[i] = strcopy[i];
      }
      strcpy(strcopy, "");
      b = 0;
    }
    printf("%s\\n", str);
  }
  return 0;
}
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, i;
  char data[2000001];
  char out[2000001];
  char r;
  int k, m;
  char num[11] = "0123456789";
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    cin >> data;
    for (int j = 0; j < n; j++) {
      k = 0;
      m = 1;
      r = data[0];
      for (i = 1; data[i] != '\\0'; i++) {
        if (data[i] == r) {
          m += 1;
        } else {
          if (m < 10) {
            out[k] = num[m];
            k += 1;
          } else if (m < 100) {
            out[k] = num[m / 10];
            k += 1;
            out[k] = num[m - m / 10 * 10];
            k += 1;
          } else {
            out[k] = num[m / 100];
            k += 1;
            out[k] = num[m / 10 - m / 100 * 10];
            k += 1;
            out[k] = num[m - m / 10 * 10];
            k += 1;
          }
          out[k] = r;
          k += 1;
          r = data[i];
          m = 1;
        }
      }
      if (m < 10) {
        out[k] = num[m];
        k += 1;
      } else if (m < 100) {
        out[k] = num[m / 10];
        k += 1;
        out[k] = num[m - m / 10 * 10];
        k += 1;
      } else {
        out[k] = num[m / 100];
        k += 1;
        out[k] = num[m / 10 - m / 100 * 10];
        k += 1;
        out[k] = num[m - m / 10 * 10];
        k += 1;
      }
      out[k] = r;
      k += 1;
      out[k] = '\\0';
      for (i = 0; out[i] != '\\0'; i++) {
        data[i] = out[i];
      }
      data[i] = '\\0';
    }
    cout << data << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, i;
  char data[101];
  char out[101];
  char r;
  int k, m;
  char num[11] = "0123456789";
  while (cin >> n) {
    if (n == 0) {
      break;
    }
    cin >> data;
    for (int j = 0; j < n; j++) {
      k = 0;
      m = 1;
      r = data[0];
      for (i = 1; data[i] != '\\0'; i++) {
        if (data[i] == r) {
          m += 1;
        } else {
          if (m < 10) {
            out[k] = num[m];
            k += 1;
          } else if (m < 100) {
            out[k] = num[m / 10];
            k += 1;
            out[k] = num[m - m / 10 * 10];
            k += 1;
          } else {
            out[k] = num[m / 100];
            k += 1;
            out[k] = num[m / 10 - m / 100 * 10];
            k += 1;
            out[k] = num[m - m / 10 * 10];
            k += 1;
          }
          out[k] = r;
          k += 1;
          r = data[i];
          m = 1;
        }
      }
      if (m < 10) {
        out[k] = num[m];
        k += 1;
      } else if (m < 100) {
        out[k] = num[m / 10];
        k += 1;
        out[k] = num[m - m / 10 * 10];
        k += 1;
      } else {
        out[k] = num[m / 100];
        k += 1;
        out[k] = num[m / 10 - m / 100 * 10];
        k += 1;
        out[k] = num[m - m / 10 * 10];
        k += 1;
      }
      out[k] = r;
      k += 1;
      out[k] = '\\0';
      for (i = 0; out[i] != '\\0'; i++) {
        data[i] = out[i];
      }
      data[i] = '\\0';
    }
    cout << data << endl;
  }
  return 0;
}
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>
int n, m;
int i, j;
char st[1000000];
char ans[10000000];
int now;
int counter;

char tochar(int a) {
  switch (a) {
  case 0:
    return '0';
  case 1:
    return '1';
  case 2:
    return '2';
  case 3:
    return '3';
  case 4:
    return '4';
  case 5:
    return '5';
  case 6:
    return '6';
  case 7:
    return '7';
  case 8:
    return '8';
  case 9:
    return '9';
  }
}

void change() {
  counter = 1;
  now = 0;
  char string[100] = "";
  int cou = 0;
  for (int k = 0; k < strlen(st) - 1; k++) {
    cou = 0;
    char a = st[k];
    char b = st[k + 1];
    if (a == b)
      counter++;
    else {
      cou = 0;
      string[0] = '\\0';
      while (counter >= 1) {
        string[cou++] = tochar(counter % 10);
        counter = (int)(counter / 10);
      }
      string[cou] = '\\0';
      for (int l = cou - 1; l >= 0; l--)
        ans[now++] = string[l];
      ans[now++] = (char)(st[k]);
      counter = 1;
    }
  }
  cou = 0;
  string[0] = '\\0';
  while (counter >= 1) {
    string[cou++] = tochar(counter % 10);
    counter = (int)(counter / 10);
  }
  string[cou] = '\\0';
  for (int l = cou - 1; l >= 0; l--) {
    ans[now++] = string[l];
  }
  ans[now++] = (char)(st[strlen(st) - 1]);
  ans[now] = '\\0';
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      return 0;
    scanf("%s", st);
    for (i = 0; i < n; i++) {
      change();
      for (j = 0; j < now; j++)
        st[j] = ans[j];
      st[now] = '\\0';
    }
    for (i = 0; i < now; i++)
      printf("%c", ans[i]);
    printf("\\n");
    ans[0] = '\\0';
  }
  printf("%s", ans);
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <string.h>
int n, m;
int i, j;
char st[1000000];
char ans[10000000];
int now;
int counter;

void change() {
  counter = 1;
  now = 0;
  for (int k = 0; k < strlen(st) - 1; k++) {
    char a = st[k];
    char b = st[k + 1];
    if (a == b)
      counter++;
    else {
      while (counter >= 1) {
        ans[now++] = (char)(counter % 10 + 48);
        counter = (int)(counter / 10);
      }
      ans[now++] = (char)(st[k]);
      counter = 1;
    }
  }
  while (counter >= 1) {
    ans[now++] = (char)(counter % 10 + 48);
    counter = (int)(counter / 10);
  }
  ans[now++] = (char)(st[strlen(st) - 1]);
  ans[now] = '\\0';
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      return 0;
    for (i = 0; i < 9999999; i++) {
      st[i] = ' ';
      ans[i] = ' ';
    }
    st[10000000] = '\\0';
    ans[10000000] = '\\0';
    scanf("%s", st);
    for (i = 0; i < n; i++) {
      change();
      for (j = 0; j < now; j++)
        st[j] = ans[j];
      st[now] = '\\0';
    }
    printf("%s\\n", ans);
    ans[0] = '\\0';
  }
}
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

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

#define Length 35000

void strpro(char *);

int main() {
  int N;
  char *str;
  str = (char *)malloc(Length * sizeof(char));
  while (scanf("%d", &N) == 1 && N) {
    scanf("%s", str);
    for (int i = 0; i < N; i++) {
      strpro(str);
    }
    puts(str);
  }
  return 0;
}

void strpro(char *var) {
  int *iList;
  char *cList;
  int len = 0;
  int counts = 1;
  iList = (int *)malloc(Length * sizeof(int));
  cList = (char *)malloc(Length * sizeof(char));
  for (char *ptr = var, *cmp = NULL; true; ptr++) {
    if (*ptr == '\\0') {
      iList[len] = counts;
      cList[len] = *cmp;
      cList[len + 1] = '\\0';
      len++;
      break;
    }
    if (ptr != var && cmp != NULL) {
      if (*ptr == *cmp) {
        counts++;
      } else {
        iList[len] = counts;
        cList[len] = *cmp;
        cList[len + 1] = '\\0';
        len++;
        counts = 1;
      }
    }
    cmp = ptr;
  }
  char *ptr = var;
  for (int i = 0; cList[i]; i++) {
    char tmp[10];
    sprintf(tmp, "%d", iList[i]);
    for (int j = 0; tmp[j]; j++) {
      *(ptr++) = tmp[j];
    }
    *(ptr++) = cList[i];
  }
  *ptr = NULL;
}

Error: 0

Fixed submission:

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

void strpro(char *);

int main() {
  int N;
  char *strA;
  strA = (char *)malloc(1000 * sizeof(char));
  while (scanf("%d", &N) == 1 && N) {
    scanf("%s", strA);
    for (int i = 0; i < N; i++) {
      strpro(strA);
    }
    puts(strA);
  }
  return 0;
}

void strpro(char *var) {
  int iList[120];
  char cList[120];
  int len = 0;
  int counts = 1;
  for (char *ptr = var, *cmp = NULL; true; ptr++) {
    if (*ptr == '\\0') {
      iList[len] = counts;
      cList[len] = *cmp;
      cList[len + 1] = '\\0';
      len++;
      break;
    }
    if (ptr != var && cmp != NULL) {
      if (*ptr == *cmp) {
        counts++;
      } else {
        iList[len] = counts;
        cList[len] = *cmp;
        cList[len + 1] = '\\0';
        len++;
        counts = 1;
      }
    }
    cmp = ptr;
  }
  char *ptr = var;
  for (int i = 0; cList[i]; i++) {
    char tmp[5];
    sprintf(tmp, "%d", iList[i]);
    for (int j = 0; tmp[j]; j++) {
      *(ptr++) = tmp[j];
    }
    *(ptr++) = cList[i];
  }
  *ptr = NULL;
}
Problem p00429 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cassert>
#include <iostream>
#define REP(i, l, n) for (int i = l; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define MAX 1000000
int n, cou, digit;
char target, current;
char a[MAX], ans[MAX];
using namespace std;
int main() {
  while (1) {
    cin >> n;
    if (n == 0)
      return 0;
    cin >> a;
    rep(i, n) {
      cou = 0;
      digit = 0;
      rep(j, MAX) {
        // cout << i << " <-i,j-> " << j << " , " << a << " <-a,ans-> " << ans
        // << endl;
        current = a[j];
        if (cou == 0 || target == current) {
          cou++;
          target = current;
        } else {
          if (cou >= 100)
            ans[digit++] = (char)(cou / 100 + '0');
          if (cou >= 10)
            ans[digit++] = (char)(cou / 10 % 10 + '0');
          ans[digit++] = (char)(cou % 10 + '0');
          ans[digit++] = target;
          cou = 1;
          target = current;
        }
        if (current == '\\0') {
          ans[digit++] = '\\0';
          break;
        }
      }
      rep(i, digit) a[i] = ans[i];
    }
    cout << a << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cassert>
#include <iostream>
#define REP(i, l, n) for (int i = l; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define MAX 100000
unsigned long long ans, a;
int n, target, current, cou, digit;
using namespace std;
int main() {
  while (1) {
    cin >> n;
    if (n == 0)
      return 0;
    cin >> a;
    current = -1;
    rep(i, n) {
      ans = 0;
      cou = 0;
      digit = 1;
      rep(j, MAX) {
        current = a % 10;
        if (cou == 0 || target == current) {
          cou++;
          target = current;
          a /= 10;
        } else {
          ans += digit * (cou * 10 + target);
          cou = 0;
          digit *= 100;
        }
        if (a == 0) {
          ans += digit * (cou * 10 + target);
          break;
        }
      }
      a = ans;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00429 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define MAXLEN 65536

int main(void) {
  int n;
  char src[MAXLEN], *p, *q;
  int ch, cnt;

  while (scanf("%d", &n), n) {
    scanf("%s", src);
    for (int i = 0; i < n; i++) {
      char buf[MAXLEN] = {0};
      ch = *src;
      cnt = 1;
      q = buf;
      for (p = src + 1; 1; p++) {
        //				printf("p=<%s>, buf=<%s>, (ch=%c, cnt=%d)\\n",
        //p, buf, ch, cnt);
        if (*p == ch) {
          cnt++;
        } else {
          char tmp[100];
          sprintf(tmp, "%d", cnt);
          strcpy(q, tmp);
          q += strlen(tmp);
          *q++ = ch;
          ch = *p;
          cnt = 1;
          if (ch == 0)
            break;
        }
      }
      strcpy(src, buf);
    }
    puts(src);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#define MAXLEN 1024

int main(void) {
  int n;
  char src[MAXLEN], *p, *q;
  int ch, cnt;

  while (scanf("%d", &n), n) {
    scanf("%s", src);
    for (int i = 0; i < n; i++) {
      char buf[MAXLEN] = {0};
      ch = *src;
      cnt = 1;
      q = buf;
      for (p = src + 1; 1; p++) {
        //				printf("p=<%s>, buf=<%s>, (ch=%c, cnt=%d)\\n",
        //p, buf, ch, cnt);
        if (*p == ch) {
          cnt++;
        } else {
          char tmp[100];
          sprintf(tmp, "%d", cnt);
          strcpy(q, tmp);
          q += strlen(tmp);
          *q++ = ch;
          ch = *p;
          cnt = 1;
          if (ch == 0)
            break;
        }
      }
      strcpy(src, buf);
    }
    puts(src);
  }
  return 0;
}
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

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

string change(int n) {
  string s = "";
  while (n > 0) {
    s += (n % 10 + '0');
    n /= 10;
  }
  reverse(s.begin(), s.end());
  return s;
}

int main() {
  int n;

  while (cin >> n, n) {
    string str;
    cin >> str;

    while (n--) {
      string tmp = "";
      int cnt = 1;
      char key = str[0];
      int size = str.size();
      str[size] = '#';
      for (int i = 1; i <= size; i++) {
        if (key == str[i]) {
          cnt++;
        } else {
          tmp += change(cnt);
          tmp += key;
          key = str[i];
          cnt = 1;
        }
      }

      str = tmp;
    }
    cout << str << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;

  while (cin >> n, n) {
    string str;
    cin >> str;

    while (n--) {
      string tmp = "";
      int cnt = 1, size = str.size();
      char key = str[0];
      str[key] = '#';
      for (int i = 1; i <= size; i++) {
        if (key == str[i]) {
          cnt++;
        } else {
          tmp += cnt + '0';
          tmp += key;
          key = str[i];
          cnt = 1;
        }
      }

      str.clear();
      str = tmp;
    }
    cout << str << endl;
  }

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

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

using namespace std;

/*
11
21
1211
111221
312211
13112221
*/
string ItoString(int num) {
  stringstream ss;
  ss << num;
  return ss.str();
}
string ope(string str) {
  string s = "";
  int len = str.size();
  int count = 1;
  char c = str[0];
  for (int i = 1; i < len; i++) {
    if (str[i] == c) {
      count++;
    } else {
      s += ItoString(count);
      s.push_back(c);
      c = str[i];
      count = 1;
    }
  }
  s += ItoString(count);
  s.push_back(c);

  return s;
}

int main() {
  int n;
  string str;
  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    }
    cin >> str;
    for (int i = 0; i < n; i++) {
      str = ope(str);
    }
    cout << str << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

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

using namespace std;

/*
11
21
1211
111221
312211
13112221
*/

string ope(string str) {
  string s = "";
  stringstream ss;
  int len = str.size();
  int count = 1;
  char c = str[0];
  for (int i = 1; i < len; i++) {
    if (str[i] == c) {
      count++;
    } else {

      ss << count;
      s += (ss.str());
      s.push_back(c);
      c = str[i];
      count = 1;
    }
  }
  ss << count;
  s += ss.str();
  s.push_back(c);

  return s;
}

int main() {
  int n;
  string str;
  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    }
    cin >> str;
    for (int i = 0; i < n; i++) {
      str = ope(str);
    }
    cout << str << endl;
  }
  return 0;
}
Problem p00429 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// sツづ個静ヲツ督ェツつゥツづァツづ個連ツ堕アツ青板づーツ陛板つキ
// sst ツづ按づァツ　return 2
int f(string s) {
  unsigned int count;
  for (count = 1; count < s.size(); count++) {
    if (s.at(count - 1) != s.at(count))
      break;
  }
  return count;
}

int main() {
  int n;
  string str;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    cin >> str;
    for (int i = 0; i < n; i++) {
      string ans;
      for (unsigned int j = 0; j < str.size();) {
        char buf[1024];
        int len = f(str.substr(j));
        sprintf(buf, "%d%c", len, str.at(j));
        ans += buf;
        j += len;
      }
      str = ans;
    }
    cout << str << endl;
  }
}

Error: TLE

Fixed submission:

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

// sツづ個静ヲツ督ェツつゥツづァツづ個連ツ堕アツ青板づーツ陛板つキ
// sst ツづ按づァツ　return 2
int f(string s) {
  unsigned int count;
  for (count = 1; count < s.size(); count++) {
    if (s.at(count - 1) != s.at(count))
      break;
  }
  return count;
}

int main() {
  int n;
  string str;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    cin >> str;
    for (int i = 0; i < n; i++) {
      string ans;
      for (unsigned int j = 0; j < str.size();) {
        char buf[1024];
        int len = f(str.substr(j));
        // sprintf_s(buf, 1024, "%d%c", len, str.at(j));
        ans += buf;
        j += len;
      }
      str = ans;
    }
    cout << str << endl;
  }
}