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

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

int main(void) {
  int n, i, j, nagasa;
  while (scanf("%d", &n), n) {
    char str[60000] = {0}, afstr[60000] = {0};
    char after;
    char *p;
    int count = 0, r = 1;

    scanf("%s", str);
    for (i = 0; i < n; i++) {

      nagasa = strlen(str);

      for (j = 0; j < nagasa; j++) {
        after = str[j + 1];
        if (after == str[j]) {
          r++;
        }

        else {
          sprintf(afstr + count, "%d", r);
          if (r >= 10)
            count++;
          r = 1;
          count++;
          afstr[count] = str[j];
          count++;
        }
      }
      count = 0;
      strcpy(str, afstr);
    }
    printf("%s\\n", afstr);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  int n, i, j, nagasa;
  while (scanf("%d", &n), n) {
    char str[60000] = {0}, afstr[60000] = {0};
    char after;
    char *p;
    int count = 0, r = 1;

    scanf("%s", str);
    for (i = 0; i < n; i++) {
      nagasa = strlen(str);
      printf("\\n\\n\\n%d\\n", i);

      for (j = 0; j < nagasa; j++) {
        after = str[j + 1];
        if (after == str[j]) {
          r++;
        }

        else {
          sprintf(afstr + count, "%d", r);
          r = 1;
          count++;
          afstr[count] = str[j];
          printf("%s\\n", afstr);
          count++;
        }
      }
      count = 0;
      strcpy(str, afstr);
    }
    printf("%s\\n", afstr);
  }
  return 0;
}
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int n, counter;
  string s, hs;
  char Sin[1000000], sets;

  while (true) {
    cin >> n;
    if (n == 0)
      break;
    cin >> s;
    hs.clear();
    while (n-- > 0) {
      sets = s[0];
      counter = 0;
      for (int i = 0; i < s.length(); i++) {

        if (sets == s[i])
          counter++;
        if (sets != s[i + 1] || i == s.length() - 1) {
          sprintf(Sin, "%d", counter);
          hs += Sin;
          hs += sets;
          sets = s[i + 1];
          counter = 0;
        }
      }
      s.clear();
      s = hs;
      hs.clear();
    }
    cout << s << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n;
  string s;
  int ans[100][10000];
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
      ans[n][i] = s[i] - '0';
    }
    int cou = 1, fl, tm = 0, hk;
    fl = s.length();
    n += 1;
    while (n-- > 0) {
      // cout << "ans[n][0] = " << ans[n][0] << endl;
      hk = ans[n][0];
      // cout << "hk = " << hk << endl;
      // cout << "fl = " << fl << endl;
      if (n == 0) {
        for (int i = 0; i < fl; i++)
          cout << ans[n][i];
        cout << endl;
      }
      for (int i = 1; i < fl; i++) {
        if (hk == ans[n][i]) {
          cou++;
        } else if (hk != ans[n][i]) {
          ans[n - 1][tm] = cou;
          ans[n - 1][tm + 1] = hk;
          tm += 2;
          cou = 1;
          hk = ans[n][i];
          // cout << "new hk = " << hk << endl;
        }
        if (i == fl - 1) {
          ans[n - 1][tm] = cou;
          ans[n - 1][tm + 1] = hk;
          tm += 2;
          ans[n - 1][tm + 2] = ans[n][i];
          cou = 1;
        }
      }
      fl = tm;
      tm = 0;
    }

    //	for(int i=0;i<10;i++){
    // for(int j=0;j<10;j++)cout << ans[i][j] << " ";
    // cout << endl;
    //}
  }
}
Problem p00429 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

string itos(int t) {
  ostringstream oss;
  oss << t;
  return oss.str();
}

string opr(string str) {
  string res = "";
  for (int i = 0; i < str.size();) {
    int idx = i + 1;
    while (idx < str.size() && str[i] == str[idx])
      idx++;
    res += itos(idx - i) + str[i];
    i = idx;
  }
  return res;
}

int main() {
  int n;
  while (cin >> n, n) {
    string str;
    cin >> str;
    for (int i = 0; i < n; i++)
      str = opr(str);
    cout << str << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

string itos(int t) {
  ostringstream oss;
  oss << t;
  return oss.str();
}

string opr(string str) {
  string res = "";
  for (int i = 0; i < str.size();) {
    int idx = i + 1;
    while (idx < str.size() && str[i] == str[idx])
      idx++;
    res += itos(idx - i) + str[i];
  }
  return res;
}

int main() {
  int n;
  while (cin >> n, n) {
    string str;
    cin >> str;
    for (int i = 0; i < n; i++)
      str = opr(str);
    cout << str << endl;
  }
}
Problem p00429 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int n;

char *moji(char *str) {
  char temp[40000];

  char sub;
  int cont = 0, i = 0, cont2 = 0;
  /*
  for(int i = 0; str[i] != '\\0'; i++){
          printf("%c",str[i]);
  }
  cout << endl;
  */
  for (;;) {
    sub = str[i];
    cont = 0;
    for (;; i++) {
      if (sub == str[i]) {
        cont++;
      } else {
        break;
      }
    }
    //	printf("%dÂÌ%c¾æ\\n",cont,sub);

    sprintf(temp + cont2, "%d\\0", cont);
    while (temp[cont2] != '\\0')
      cont2++;

    temp[cont2] = sub;
    //	printf("temp[%d] = %c\\n",cont2,sub);
    cont2++;

    if (str[i] == '\\0') {
      temp[cont2] = '\\0';
      break;
    }
  }

  n--;
  if (n == 0) {
    for (int i = 0; temp[i] != '\\0'; i++) {
      if (isspace(temp[i]) == 1) {
        break;
      }
      printf("%c", temp[i]);
    }
    cout << endl;
    return 0;
  } else {
    /*
    for(int i = 0; temp[i] != '\\0'; i++){
            printf("%c",temp[i]);
    }
    cout << endl;
    */
    return moji(temp);
  }
}

int main() {
  char temp[40000];
  for (;;) {
    cin >> n;
    if (n == 0) {
      break;
    }
    cin >> temp;
    moji(temp);
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int n;

char *moji(char str[]) {
  char temp[1000];
  char sub;
  int cont = 0, i = 0, cont2 = 0;
  /*
  for(int i = 0; str[i] != '\\0'; i++){
          printf("%c",str[i]);
  }
  cout << endl;
  */
  for (;;) {
    sub = str[i];
    cont = 0;
    for (;; i++) {
      if (sub == str[i]) {
        cont++;
      } else {
        break;
      }
    }
    //	printf("%dÂÌ%c¾æ\\n",cont,sub);

    temp[cont2] = cont + 48;
    //	printf("temp[%d] = %d\\n",cont2,cont);
    cont2++;

    temp[cont2] = sub;
    //	printf("temp[%d] = %c\\n",cont2,sub);
    cont2++;

    if (str[i] == '\\0') {
      temp[cont2] = '\\0';
      break;
    }
  }

  n--;
  if (n == 0) {
    for (int i = 0; temp[i] != '\\0'; i++) {
      printf("%c", temp[i]);
    }
    cout << endl;
    return 0;
  } else {
    /*
    for(int i = 0; temp[i] != '\\0'; i++){
            printf("%c",temp[i]);
    }
    cout << endl;
    */
    return moji(temp);
  }
}

int main() {

  char temp[1000];
  for (;;) {
    cin >> n;
    if (n == 0) {
      break;
    }
    cin >> temp;
    moji(temp);
  }
}
Problem p00430 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>

using namespace std;

int m[31], n;

void dfs(int h, int l, int last) {
  int i;
  if (l == 0) {
    for (i = 0; i < h; i++)
      printf(i < h - 1 ? "%d " : "%d\\n", m[i]);
    return;
  }
  for (i = min(l, last); i > 0; i--) {
    m[h] = i;
    dfs(h + 1, l - i, i);
  }
  return;
}

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

Error: TLE

Fixed submission:

#include <stdio.h>

int m[31], n;

void dfs(int h, int l) {
  int i;
  if (l == 0) {
    for (i = 0; i < h; i++)
      printf(i < h - 1 ? "%d " : "%d\\n", m[i]);
    return;
  }
  for (i = l; i > 0; i--) {
    m[h] = i;
    dfs(h + 1, l - i);
  }
  return;
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    dfs(0, n);
  }
  return 0;
}
Problem p00430 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

typedef pair<int, int> pii;

#define rep(i, j) for (int i = 0; i < (j); i++)
#define reps(i, j, k) for (int i = j; i <= k; i++)

void pr(vector<int> *r, int d) {
  rep(i, d + 1) printf("%d%c", (*r)[i], i == d ? '\\n' : ' ');
}

void f(vector<int> *r, int d, int m, int n) {
  (*r)[d] = min(m, n);
  if (n == 0)
    pr(r, d - 1);
  if (d < r->size())
    for (int i = (*r)[d]; i-- > 0; (*r)[d]--)
      f(r, d + 1, (*r)[d], n - (*r)[d]);
}

int main() {
  int n;
  for (;;) {
    scanf("%d", &n);
    if (n == 0)
      break;
    vector<int> v(n);
    f(&v, 0, n, n);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

typedef pair<int, int> pii;

#define rep(i, j) for (int i = 0; i < (j); i++)
#define reps(i, j, k) for (int i = j; i <= k; i++)

void pr(vector<int> *r, int d) {
  int f = 1;
  reps(i, 1, d) if ((*r)[i] > (*r)[i - 1]) f = 0;
  if (f)
    rep(i, d + 1) printf("%d%c", (*r)[i], i == d ? '\\n' : ' ');
}

void f(vector<int> *r, int d, int m, int n) {
  // if(n==0)
  (*r)[d] = min(m, n);
  pr(r, d);
  if (d < r->size())
    while (--(*r)[d] > 0) {
      n++;
      f(r, d + 1, m - (*r)[d], n);
    }
}

int main() {
  int n;
  for (;;) {
    scanf("%d", &n);
    if (n == 0)
      break;
    vector<int> v(n);
    f(&v, 0, n, n);
  }
  return 0;
}
Problem p00430 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

char str[200];
void search(int rest, int last, int strpos) {
  if (rest == 0) {
    printf("%s\\n", str + 1);
  }
  for (int i = min(rest, last); i > 0; i--) {
    search(rest - i, i, strpos + sprintf(str + strpos, " %d", i));
  }
}

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

int main() {
  while (true) {
    int n;
    scanf("%d", &n);
    if (n == 0)
      break;
    char *str = new char[102];
    scanf("%s", str);
    while (n--) {
      strcat(str, "x");
      char *str2 = new char[strlen(str) * 2 + 2];
      int idx = 0;
      char last = str[0];
      int cnt = 1;
      for (int i = 1; str[i]; i++) {
        if (last == str[i]) {
          cnt++;
        } else {
          idx += sprintf(str2 + idx, "%d%c", cnt, last);
          last = str[i];
          cnt = 1;
        }
      }
      delete[] str;
      str = str2;
    }
    printf("%s\\n", str);
  }
  return 0;
}
Problem p00430 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif

#define foreach(it, c)                                                         \\
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int n;
  while (scanf("%d", &n), n) {
    int b[31];
    memset(b, 0, sizeof(b));
    b[0] = n;
    while (true) {
      int t = find(b, b + n, 0) - b;
      for (int i = 0; i < t - 1; ++i)
        printf("%d ", b[i]);
      printf("%d\\n", b[t - 1]);

      if (t == n)
        break;

      int u;
      u = t - 1;
      while (b[u] == 1)
        --u;
      --b[u];
      ++u;
      fill(b + u, b + n, 0);
      int s = t - u + 1;
      while (s--) {
        if (b[u] == b[u - 1])
          ++u;
        ++b[u];
      }
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif

#define foreach(it, c)                                                         \\
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int n;
  while (scanf("%d", &n), n) {
    int b[16];
    memset(b, 0, sizeof(b));
    b[0] = n;
    while (true) {
      int t = find(b, b + n, 0) - b;
      for (int i = 0; i < t - 1; ++i)
        printf("%d ", b[i]);
      printf("%d\\n", b[t - 1]);

      if (t == n)
        break;

      int u;
      u = t - 1;
      while (b[u] == 1)
        --u;
      --b[u];
      ++u;
      fill(b + u, b + n, 0);
      int s = t - u + 1;
      while (s--) {
        if (b[u] == b[u - 1])
          ++u;
        ++b[u];
      }
    }
  }
}
Problem p00430 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n;

void solve(vector<int> &sq, int idx) {
  bool output = true;
  for (int i = 0; i < n - 1; ++i) {
    if (sq[i] < sq[i + 1]) {
      output = false;
      break;
    }
  }

  if (output) {
    printf("%d", sq[0]);
    for (int i = 1; i < n; ++i) {
      if (sq[i] == 0)
        break;
      printf(" %d", sq[i]);
    }
    puts("");
  }

  int init = 1;
  if (idx != 0 && sq[idx - 1] < sq[idx])
    init = sq[idx] - sq[idx - 1];

  for (int i = init; sq[idx] - i > 0; ++i) {
    sq[idx] -= i;
    sq[idx + 1] += i;
    solve(sq, idx + 1);
    sq[idx + 1] -= i;
    sq[idx] += i;
  }
}

int main() {
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;
    vector<int> sq(n, 0);
    sq[0] = n;
    solve(sq, 0);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int n;

bool valid(const vector<int> &sq) {
  for (int i = 0; i < n - 1; ++i) {
    if (sq[i] < sq[i + 1])
      return false;
  }
  return true;
}

void solve(vector<int> sq, int idx) {
  if (valid(sq)) {
    printf("%d", sq[0]);
    for (int i = 1; i < n; ++i) {
      if (sq[i] == 0)
        break;
      printf(" %d", sq[i]);
    }
    puts("");
  }

  while (sq[idx] > 1) {
    --sq[idx];
    ++sq[idx + 1];
    solve(sq, idx + 1);
  }
}

int main() {
  while (~scanf("%d", &n)) {
    vector<int> sq(n, 0);
    sq[0] = n;
    solve(sq, 0);
  }
  return 0;
}
Problem p00430 (C++) — buggy submission, verdict: Time Limit Exceeded

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

set<vector<int>> data;

void rec(vector<int> d, int last) {
  data.insert(d);
  for (int i = 0; i < last; i++) {
    if (i && d[i] + 1 > d[i - 1])
      continue;
    d[last]--, d[i]++;
    if (data.find(d) == data.end())
      rec(d, d[last] == 0 ? last - 1 : last);
    d[last]++, d[i]--;
  }
}

int main() {
  int n;
  while (cin >> n, n) {
    vector<int> d(n, 1);
    set<vector<int>> emp;
    data = emp;
    rec(d, n - 1);
    for (set<vector<int>>::reverse_iterator it = data.rbegin();
         it != data.rend(); ++it) {
      for (int j = 0; j < (*it).size(); j++)
        if ((*it)[j])
          cout << (j ? " " : "") << (*it)[j];
      cout << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
void rec(vector<int> data) {
  bool flag = true;
  for (int i = 0; i + 1 < data.size(); i++) {
    if (data[i] < data[i + 1])
      flag = false;
  }
  if (flag) {
    for (int i = 0; i < data.size(); i++) {
      printf("%d%c", data[i], i == data.size() - 1 ? 10 : 32);
    }
  }
  for (int i = 1; i < data[data.size() - 1]; i++) {
    data[data.size() - 1] -= i;
    data.push_back(i);
    rec(data);
    data.pop_back();
    data[data.size() - 1] += i;
  }
}

int main() {
  vector<int> data(1);
  while (cin >> data[0], data[0]) {
    rec(data);
  }
}
Problem p00430 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_str(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef long long ll;

void printa(vector<int> &a) {
  for (int i = 0; i < a.size(); i++) {
    printf("%d%s", a[i], (i == a.size() - 1 ? "\\n" : " "));
  }
}

void judge(vector<int> &num, int n, int prev) {
  if (n == 0) {
    printa(num);
  }
  for (int i = n; i > 0; i--) {
    if (prev < i) {
      continue;
    }
    num.push_back(i);
    judge(num, n - i, i);
    num.pop_back();
  }
  return;
}

/*
   0 , 5
   5 , 0

   4 , 1
   4 1 , 0

   3 , 2
   3 2, 0

   3 1 , 1
   3 1 1, 0

   2 , 3
   2 3 , 0

   2 2 , 1
   2 2 1 ,0

   1, 4
   1 4, 0

   1 3, 1
   1 3 1, 0
   1 2, 2
   1 2 2, 0
   1 2 1 1, 0

   1 1 , 3
   1 1 3 , 0

   1 1  ,
   1 1 1 1 , 0
   1
   */
int main() {
  int n;
  while (cin >> n) {
    vector<int> num;
    judge(num, n, 100);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_str(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef long long ll;

void printa(vector<int> &a) {
  for (int i = 0; i < a.size(); i++) {
    printf("%d%s", a[i], (i == a.size() - 1 ? "\\n" : " "));
  }
}

void judge(vector<int> &num, int n) {
  if (n == 0) {
    bool j = true;
    for (int i = 0; i < num.size() - 1; i++) {
      if (num[i] < num[i + 1]) {
        j = false;
        break;
      }
    }
    if (j) {
      printa(num);
    }
  }
  for (int i = n; i > 0; i--) {
    num.push_back(i);
    judge(num, n - i);
    num.pop_back();
  }
  return;
}

/*
   0 , 5
   5 , 0

   4 , 1
   4 1 , 0

   3 , 2
   3 2, 0

   3 1 , 1
   3 1 1, 0

   2 , 3
   2 3 , 0

   2 2 , 1
   2 2 1 ,0

   1, 4
   1 4, 0

   1 3, 1
   1 3 1, 0
   1 2, 2
   1 2 2, 0
   1 2 1 1, 0

   1 1 , 3
   1 1 3 , 0

   1 1  ,
   1 1 1 1 , 0
   1
   */
int main() {
  int n;
  while (cin >> n) {
    vector<int> num;
    judge(num, n);
  }
}
Problem p00430 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstdlib>
#include <iostream>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define MAX 35
using namespace std;

void reset(int a[], int from) {
  for (int i = from; i < MAX; i++) {
    a[i] = 0;
  }
}
void show(int array[]) {
  int temp = 0;
  while (array[temp + 1] != 0 && temp < MAX) {
    printf("%d ", array[temp]);
    temp++;
  }
  printf("%d\\n", array[temp]);
}

void dfs(int *a) {
  show(a);
  if (a[0] == 1)
    return;
  int last = 0;
  for (last = 0; a[last + 1] != 0 && last < MAX; last++)
    ;
  if (a[last] != 1) {
    a[last]--;
    a[++last]++;
    dfs(a);
  } else {
    int sum = 0;
    for (int temp = last; temp >= 0; temp--) {
      sum += a[temp];
      if (a[temp] == 2) {
        a[temp] = 1;
        a[++last]++;
        dfs(a);
        break;
      } else if (a[temp] >= 3) {
        int mow = a[temp] - 1;
        reset(a, temp);
        while (sum > mow) {
          a[temp++] = mow;
          sum -= mow;
        }
        a[temp] = sum;
        dfs(a);
        break;
      }
    }
  }
  return;
}

int main() {
  int n;
  int array[MAX];
  while (scanf("%d", &n), n != 0) {
    reset(array, 0);
    array[0] = n;
    dfs(array);
  }
  return 0;
}

Error: 2

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <iostream>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define MAX 35
using namespace std;

void reset(int a[]) {
  rep(i, MAX) { a[i] = 0; }
}
void show(int array[]) {
  int temp = 0;
  while (array[temp + 1] != 0 && temp < MAX) {
    printf("%d ", array[temp]);
    temp++;
  }
  printf("%d\\n", array[temp]);
}

void dfs(int *a) {
  show(a);
  if (a[1] == 0 || a[1] == 1)
    return;
  int last = 0;
  for (last = 0; a[last + 1] != 0 && last < MAX; last++)
    ;
  if (a[last] != 1) {
    a[last]--;
    a[++last]++;
    dfs(a);
  } else {
    for (int temp = last - 1; temp >= 1; temp--) {
      if (a[temp] == 2) {
        a[temp] = 1;
        a[++last]++;
        dfs(a);
        break;
      } else if (a[temp] >= 3) {
        a[temp]--;
        a[temp + 1]++;
        dfs(a);
        break;
      }
    }
  }
  return;
}

int main() {
  int n;
  int array[MAX];
  while (scanf("%d", &n), n != 0) {
    for (int now = n; now > 0; now--) {

      reset(array);
      int temp = n;
      int last = 0;
      while (temp > now) {
        array[last] = now;
        last++;
        temp -= now;
      }
      array[last] = temp;
      dfs(array);
    }
  }
  return 2;
}