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

#include <algorithm>
#include <iostream>
#include <math.h>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
int SumOfIntegers(int n, int s) {
  if (n < 0 || s < 0)
    return 0;
  if (n == 1)
    return ((s < 10) ? 1 : 0);
  int a[10], count = 0, sum;
  REP(i, 10) a[i] = i;
  do {
    sum = 0;
    REP(i, n) sum += a[i];
    if (sum == s)
      count++;
  } while (next_permutation(a, a + sizeof(a) / sizeof(a[0])));
  int d = 1;
  for (int i = 10 - n; i > 0; i--)
    d *= i;
  for (int i = 2; i <= n; i++)
    d *= i;
  return (count / d);
}

int main(void) {
  int n, s;
  while (cin >> n >> s, n) {
    cout << SumOfIntegers(n, s) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
int SumOfIntegers(int n, int s) {
  if (n < 0 || s < 0)
    return 0;
  int a[10], count = 0, sum;
  REP(i, 10) a[i] = i;
  while (next_permutation(a, a + sizeof(a) / sizeof(a[0]))) {
    sum = 0;
    REP(i, n) sum += a[i];
    if (sum == s)
      count++;
  }
  int d = 6;
  for (int i = 10 - n; i > 0; i--)
    d *= i;
  return (count / d);
}

int main(void) {
  int n, s;
  while (cin >> n >> s, n) {
    cout << SumOfIntegers(n, s) << endl;
  }
  return 0;
}
Problem p00030 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15 + 9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, s;
int ans = 0;

void dfs(long long i, long long sum, long long num) {
  if (i == n && sum == s) {
    ans++;
    return;
  }

  for (int j = num; j <= 9; j++) {
    dfs(i + 1, sum + j, j + 1);
  }
  return;
}

int main() {
  while (cin >> n >> s) {
    if (n + s == 0)
      break;
    ans = 0;
    dfs(0, 0, 0);
    cout << ans << endl;
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15 + 9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, s;
int ans = 0;

void dfs(int i, int sum, int num) {
  if (i == n && sum == s) {
    ans++;
    return;
  }

  for (int j = num; j < 10; j++) {
    dfs(i + 1, sum + j, j);
  }
  return;
}

int main() {
  while (cin >> n >> s) {
    if (n + s == 0)
      break;
    ans = 0;
    dfs(0, 0, 0);
    cout << ans << endl;
  }
}
Problem p00030 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> PL;

int n, s;
bool d[10];
int ans = 0;
vector<vector<int>> C;

void dfs(int i, int sum, int num) {
  if (i == n && sum == s) {
    ans++;
    return;
  }

  for (int j = num; j < 10; j++) {
    if (d[j] == 0) {
      d[j] = 1;
      dfs(i + 1, sum + j, j);
      d[j] = 0;
    }
  }
  return;
}

int main() {
  while (cin >> n >> s) {
    if (n + s == 0)
      break;
    dfs(0, 0, 0);
    cout << ans << endl;
    ans = 0;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> PL;

int n, s;
bool d[10];
vector<vector<int>> C;

void dfs(int i, int sum) {
  if (i == n && sum == s) {
    vector<int> vi;
    if (C.empty()) {
      REP(j, 10) {
        if (d[j] == 1) {
          vi.push_back(j);
        }
      }
      C.push_back(vi);
      return;
    }
    bool f = 1;
    REP(j, C.size()) {
      int co = 0;
      REP(k, n) {
        if (d[C[j][k]] == 1)
          co++;
      }
      if (co == n) {
        f = 0;
        break;
      }
    }
    if (f) {
      REP(j, 10) {
        if (d[j] == 1) {
          vi.push_back(j);
        }
      }
      C.push_back(vi);
    }
  }

  for (int j = 0; j < 10; j++) {
    if (d[j] == 0) {
      d[j] = 1;
      dfs(i + 1, sum + j);
      d[j] = 0;
    }
  }
  return;
}

int main() {
  while (cin >> n >> s) {
    if (n + s == 0)
      break;
    dfs(0, 0);
    cout << C.size() << endl;
    C.clear();
  }
}
Problem p00030 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

int n, sum, ans;

void solve(int n, int sum, int less);

int main() {
  while (true) {
    ans = 0;
    std::cin >> n >> sum;
    if (n == 0 && sum == 0)
      break;
    solve(n, sum, 0);
    std::cout << ans << std::endl;
  }
  return 0;
}

void solve(int n, int sum, int less) {
  if (n == 0) {
    if (sum == 0) {
      ++ans;
      return;
    }
  }

  for (int i = less; i < 10; ++i) {
    if (sum - i >= 0)
      solve(n - 1, sum - i, i + 1);
  }

  return;
}

Error: TLE

Fixed submission:

#include <iostream>

int n, sum, ans;

void solve(int n, int sum, int less);

int main() {
  while (true) {
    ans = 0;
    std::cin >> n >> sum;
    solve(n, sum, 0);
    std::cout << ans << std::endl;
  }
  return 0;
}

void solve(int n, int sum, int less) {
  if (n == 0) {
    if (sum == 0) {
      ++ans;
      return;
    }
  }

  if (sum == 0)
    return;

  for (int i = less; i < 10; ++i)
    solve(n - 1, sum - i, i + 1);

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

#include <stdio.h>
#include <string.h>
int main() {
  int i, left, tmp;
  int w[10];
  int first;
  while (scanf("%d", &left) != EOF) {
    memset(w, 0, sizeof(w));
    for (i = 9; i >= 0; i--) {
      tmp = 1 << i;
      if (left >= tmp) {
        w[i] = 1;
        left -= tmp;
      }
    }
    first = 1;
    for (i = 0; i < 10; i++) {
      if (w[i]) {
        if (first)
          printf("%d", 1 << i);
        else
          printf(" %d", 1 << i);
        first = 0;
      }
    }
    printf("\\n");
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>
int main() {
  int i, left, tmp;
  int w[10];
  char c;
  while (scanf("%d", &left) != EOF) {
    memset(w, 0, sizeof(w));
    for (i = 9; i >= 0; i--) {
      tmp = 1 << i;
      if (left >= tmp) {
        w[i] = 1;
        left -= tmp;
      }
    }
    c = '\\0';
    for (i = 0; i < 10; i++) {
      if (w[i]) {
        printf("%c%d", c, 1 << i);
        fprintf(stderr, "%c%d", c, 1 << i);
        c = ' ';
      }
    }
    printf("\\n");
  }
  return 0;
}
Problem p00031 (C++) — buggy submission, verdict: Runtime Error

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

int main(int argc, const char *argv[]) {
  int cu[11] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024};
  int g, j, cu2[10];
  while (cin >> g) {
    for (int i = 0; i < 10; i++)
      cu2[i] = 0;
    j = 0;
    for (int i = 0; i < 11; i++) {
      if ((g - cu[i]) < 0) {
        g -= cu[i - 1];
        cu2[j] = cu[i - 1];
        i = 0;
        j++;
      }
      if (g == 0)
        break;
    }
    for (int i = 0; i < j / 2; i++) {
      int tmp;
      tmp = cu2[j - 1 - i];
      cu2[j - 1 - i] = cu2[i];
      cu2[i] = tmp;
    }
    for (int i = 0; i < j; i++) {
      printf("%d", cu2[i]);
      if (i + 1 < j)
        printf(" ");
    }
    puts("");
  }
  return 0;
}

Error: WA

Fixed submission:

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

int main(int argc, const char *argv[]) {
  int cu[11] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024};
  int g, j = 0, cu2[10] = {0};
  while (cin >> g) {
    for (int i = 0; i < 11; i++) {
      if ((g - cu[i]) < 0) {
        g -= cu[i - 1];
        cu2[j] = cu[i - 1];
        i = 0;
        j++;
      }
      if (g == 0)
        break;
    }
    for (int i = 0; i < j / 2; i++) {
      int tmp;
      tmp = cu2[j - 1 - i];
      cu2[j - 1 - i] = cu2[i];
      cu2[i] = tmp;
    }
    for (int i = 0; i < j; i++) {
      printf("%d ", cu2[i]);
    }
    puts("");
  }
  return 0;
}
Problem p00031 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

using namespace std;

const int Weit = 2;
int weit;
int date;
bool flag;

int main() {
  while (scanf("%d", &date) != EOF) {
    flag = true;
    for (int i = 0; i < 10; i++) {
      if (i == 0)
        weit = Weit;
      else
        weit *= 2;
      if (date % weit != 0) {
        date -= date % weit;
        if (flag == true)
          flag = false;
        else
          printf(" ");
        printf("%d", weit / 2);
      }
    }
    printf("\\n");
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

using namespace std;

const int Weit = 2;
int weit;
int date;
bool flag;

int main() {
  while (true) {
    flag = true;
    scanf("%d", &date);
    for (int i = 0; i < 10; i++) {
      if (i == 0)
        weit = Weit;
      else
        weit *= 2;
      if (date % weit != 0) {
        date -= date % weit;
        if (flag == true)
          flag = false;
        else
          printf(" ");
        printf("%d", weit / 2);
      }
    }
    printf("\\n");
  }
  return 0;
}
Problem p00031 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n, tmp[10] = {512, 256, 128, 64, 32, 16, 8, 4, 2, 1};
  while (cin >> n && n != EOF) {
    int cnt[10] = {0};
    for (int i = 0; i < 10; i++) {
      if (n - tmp[i] >= 0) {
        n -= tmp[i];
        cnt[i]++;
      }
      if (n == 0)
        break;
    }
    int flg = 0;
    for (int i = 9; i >= 0; i--) {
      if (cnt[i] == 1) {
        if (flg == 1)
          cout << " ";
        cout << tmp[i];
        flg = 1;
      }
    }
    cout << endl;
  }
}

Error: -11

Fixed submission:

// 0031
// include-------------------------------------
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>

using namespace std;

// typedef--------------------------------------
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define MP make_pair

// repetition-----------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

// constant-------------------------------------
const double PI = acos(-1.0);

// cout,cin-------------------------------------
#define COUT(x) cout << (x) << endl;
#define CIN(x) cin >> (x);

const int weight[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};

int main() {

  int w;
  while (1) {
    vector<int> v;
    CIN(w)
    int p = 0;
    for (int i = 9; i >= 0; i--) {
      if (w >= weight[i]) {
        v[p] = weight[i];
        p++;
        w -= weight[i];
      }
    }

    for (int i = v.size(); i >= 0; i--) {
      cout << v[v.size() - i];
      if (i > 0)
        cout << " ";
    }

    cout << endl;
  }

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

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> weights;
  vector<int> use;
  weights.push_back(1);
  weights.push_back(2);
  weights.push_back(4);
  weights.push_back(8);
  weights.push_back(16);
  weights.push_back(32);
  weights.push_back(64);
  weights.push_back(128);
  weights.push_back(256);
  weights.push_back(512);
  int w;

  while (cin >> w, !cin.eof()) {
    while (w != 0) {
      for (int i = 0; i < weights.size(); i++) {
        if (w == 0)
          break;
        if (w >= 512) {
          w -= 512;
          use.push_back(512);
        } else if (weights.at(i) > w) {
          w -= weights.at(i - 1);
          use.push_back(weights.at(i - 1));
          break;
        }
      }
    }
    sort(use.begin(), use.end());
    for (int i = 0; i < use.size() - 1; i++) {
      cout << use[i] << " ";
    }
    cout << use[use.size() - 1] << endl;
    use.clear();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  vector<int> weights;
  vector<int> use;
  weights.push_back(1);
  weights.push_back(2);
  weights.push_back(4);
  weights.push_back(8);
  weights.push_back(16);
  weights.push_back(32);
  weights.push_back(64);
  weights.push_back(128);
  weights.push_back(256);
  int w;

  while (cin >> w, !cin.eof()) {
    while (w != 0) {
      for (int i = 0; i < weights.size(); i++) {
        if (w == 0)
          break;
        if (weights.at(i) > w) {
          w -= weights.at(i - 1);
          use.push_back(weights.at(i - 1));
          break;
        }
      }
    }
    sort(use.begin(), use.end());
    for (int i = 0; i < use.size() - 1; i++) {
      cout << use[i] << " ";
    }
    cout << use[use.size() - 1] << endl;
    use.clear();
  }
  return 0;
}
Problem p00031 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
using namespace std;
int n, s;
int main() {
  while (cin >> n) {
    s = 0;
    for (int i = 0; i < 31; i++) {
      if (n % 2 == 1) {
        if (s) {
          cout << ' ';
        }
        cout << pow(2, i);
        s++;
        n -= 1;
      }
      n /= 2;
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int n, s;
int main() {
  while (true) {
    cin >> n;
    s = 0;
    if (!n) {
      break;
    }
    for (int i = 1; i < 31; i++) {
      if ((n / (int)pow(2, i)) % 2 == 1) {
        if (s) {
          cout << ' ';
        }
        cout << pow(2, i - 1);
        s++;
      }
    }
    cout << endl;
  }
}
Problem p00031 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int inf = 1000000000;

int main(void) {

  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int a = 1024;
    vector<int> b;
    while (a != 0) {
      if (n / a != 0) {
        n %= a;
        b.push_back(a);
      }
      a /= 2;
    }
    for (int i = 0; i < b.size(); i++) {
      if (i != b.size() - 1)
        cout << b[b.size() - 1 - i] << " ";
      else
        cout << b[b.size() - 1 - i] << endl;
    }
  }

  return 0;
}

// EOF

Error: 0
5
7
127


Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int inf = 1000000000;

int main(void) {

  int n;
  while (cin >> n) {
    cerr << n << endl;
    if (n == 0)
      break;
    int a = 1024;
    vector<int> b;
    while (a != 0) {
      if (n / a != 0) {
        n %= a;
        b.push_back(a);
      }
      a /= 2;
    }
    for (int i = 0; i < b.size(); i++) {
      if (i != b.size() - 1)
        cout << b[b.size() - 1 - i] << " ";
      else
        cout << b[b.size() - 1 - i] << endl;
    }
  }

  return 0;
}

// EOF
Problem p00031 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int M, scale[10];
  scale[0] = 1;
  for (int i = 1; i < 10; i++) {
    scale[i] = scale[i - 1] * 2;
  }
  while (cin >> M) {
    int i = 0;
    int count = 2;
    while (true) {
      if (M == 0)
        break;
      if (M % count != 0) {
        M -= scale[i];
        if (M != 0) {
          cout << scale[i] << " ";
        } else {
          cout << scale[i] << endl;
        }
      }
      i++;
      count *= 2;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int scale[10];
  scale[0] = 1;
  for (int i = 1; i < 10; i++) {
    scale[i] = scale[i - 1];
  }
  while (true) {
    int M, i = 0;
    cin >> M;
    int count = 2;
    while (true) {
      if (M == 0)
        break;
      if (M % count != 0) {
        M -= scale[i];
      }
      cout << scale[i] << " ";
      i++;
      count *= 2;
    }
    cout << endl;
  }
}
Problem p00031 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  while (cin >> n) {
    int tmp = 0;
    vector<int> ans;
    for (int i = 9; i >= 0; i--) {
      if (n - pow(2, i) >= 0) {
        ans.push_back(pow(2, i));
        n -= pow(2, i);
      }
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size() - 1; i++) {
      cout << ans[i] << " ";
      tmp = i + 1;
    }
    cout << ans[tmp] << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  int tmp;
  while (cin >> n) {
    vector<int> ans;
    for (int i = 9; i >= 0; i--) {
      if (n - pow(2, i) >= 0) {
        ans.push_back(pow(2, i));
        n -= pow(2, i);
      }
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size() - 1; i++) {
      cout << ans[i] << " ";
      tmp = i;
    }
    cout << ans[tmp + 1] << endl;
  }
}
Problem p00031 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  int weight;
  int n;

  while (cin >> weight) {
    vector<int> result;
    while (1) {
      if (weight == 0 || weight == 1 || weight == 2 || weight == 4 ||
          weight == 8 || weight == 16 || weight == 32 || weight == 64 ||
          weight == 128 || weight == 256 || weight == 512) {
        result.push_back(weight);
        break;
      }
      if (weight < 4)
        n = 2;
      else if (weight < 8)
        n = 4;
      else if (weight < 16)
        n = 8;
      else if (weight < 32)
        n = 16;
      else if (weight < 64)
        n = 32;
      else if (weight < 128)
        n = 64;
      else if (weight < 256)
        n = 128;
      else if (weight < 512)
        n = 256;
      else
        n = 512;

      result.push_back(n);
      weight -= n;
    }

    sort(result.begin(), result.end());

    int flag = 0;
    for (auto i : result) {
      if (flag == 1)
        cout << " ";
      else
        flag = 1;
      cout << i;
    }

    cout << endl;
    result.clear();
  }
}

Error: TLE

Fixed submission:

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

int main() {

  int weight;
  int n;

  while (cin >> weight, weight) {
    vector<int> result;
    while (1) {
      if (weight == 1 || weight == 2 || weight == 4 || weight == 8 ||
          weight == 16 || weight == 32 || weight == 64 || weight == 128 ||
          weight == 256 || weight == 512) {
        result.push_back(weight);
        break;
      }

      n = weight / 2 + weight % 2;

      result.push_back(n);
      weight -= n;
    }

    sort(result.begin(), result.end());

    for (auto i : result)
      cout << i << " ";
    cout << endl;
  }
}
Problem p00031 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
  bool f = false;
  int num[10] = {};
  int N, cou = 0, jj = 0, sum = 0;
  while (scanf("%d", &N) != EOF) {
    jj = 0;
    cou = 0;
    sum = 0;
    f = false;
    do {
      num[jj] = N % 2;
      cou++;
      jj++;
      N = N / 2;
    } while (N != 0);
    for (int i = 0; i < cou; i++) {
      if (num[i] == 1) {

        sum = pow(2, (double)(i));
        if (f == true)
          cout << " ";
        cout << sum;
        f = true;
      }
    }
    cout << endl;
  }
  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
  int num[10] = {};
  int N, cou = 0, jj = 0, sum = 0;
  while (scanf("%d", &N) != EOF) {
    do {
      num[jj] = N % 2;
      cou++;
      jj++;
      N = N / 2;
    } while (N != 0);
    for (int i = 0; i < cou; i++) {
      if (num[i] == 1) {

        sum = pow(2, (double)(i));
        if (i > 0)
          cout << " ";
        cout << sum;
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p00031 (C++) — buggy submission, verdict: Runtime Error

#include <bits //stdc++.h>
using namespace std;

int main() {
  int n;
  vector<int> v;
  while (cin >> n) {
    if (n % 2 == 1) {
      n -= 1;
      v.push_back(1);
    }

    if (n % 4 == 2) {
      n -= 2;
      v.push_back(2);
    }

    if (n % 8 == 4) {
      n -= 4;
      v.push_back(4);
    }

    if (n % 16 == 8) {
      n -= 8;
      v.push_back(8);
    }

    if (n % 32 == 16) {
      n -= 16;
      v.push_back(16);
    }

    if (n % 64 == 32) {
      n -= 32;
      v.push_back(32);
    }

    if (n % 128 == 64) {
      n -= 64;
      v.push_back(64);
    }

    if (n % 256 == 128) {
      n -= 128;
      v.push_back(128);
    }

    if (n % 512 == 256) {
      n -= 256;
      v.push_back(256);
    }

    if (n % 1024 == 512) {
      n -= 512;
      v.push_back(512);
    }
    int a = v.size();
    for (int i = 0; i < a; i++) {
      cout << v[i];
      if (i == a - 1) {
        cout << endl;
      } else {
        cout << " ";
      }
    }
    v.erase(v.begin(), v.end());
  }
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int we[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
  int n;
  vector<int> v;
  vector<int>::iterator pv = v.begin();
  while (cin >> n) {
    int h = 9;
    while (n == 0) {
      if (n - we[h] >= 0) {
        n -= we[h];
        v.push_back(h);
      }
      h--;
    }
    for (int i = v.size(); i > -1; i--) {
      int x = v[i];
      cout << we[x];
      if (i != 0) {
        cout << " ";
      } else {
        cout << endl;
      }
    }
  }
  return 0;
}