167872025-05-13 11:15:06ercseferencÖsszegzésekcpp17Forditási hiba
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,s=0;cin>>n;
    int b[n];
    for(int i=0; i<n; i++){cin>>b[i]; s+=b[i];}
    int a[s];
    for(int i=0; i<s; i++){
        if(i<n)a[i]=b[i];
        else a[i]=0;}
    /*int k=s-1;
    while(a[k]==0)k--;
    if(k==0)cout<<0;
    else{
        int p=a[k]-1; k--;
        while(a[k]==a[k-1]){
            p+=a[k]; k--;}
        a[k]++;
        for(int i=1; i<=p; i++)a[k+i]=1;
        for(int i=k+p+1; i<s; i++)a[i]=0;
        for(int i=0; i<=k+p; i++)cout<<a[i]<<" ";}
    cout<<endl;*/ k=s-1;
    for(int i=0; i<s; i++){
        if(i<n)a[i]=b[i];
        else a[i]=0;}
    while(a[k]<2 && k>=0)k--;
    if(k==-1)cout<<0;
    else{
        a[k]--; int p=0,c=a[k];
        for(int i=0; i<=k; i++){p+=a[i];}
        p=s-p;
        for(int i=k+1; i<s; i++){a[i]=0;}
        k++;
        while(p-c>0){a[k]=c; k++; p-=c;}
        a[k]=p; int t=0;
        while(a[t]!=0){cout<<a[t]<<" "; t++;}}
    return 0;
}
Forditási hiba
open /var/local/lib/isolate/433/box/a.out: no such file or directory
main.cpp: In function 'int main()':
main.cpp:25:19: error: 'k' was not declared in this scope
   25 |     cout<<endl;*/ k=s-1;
      |                   ^