using namespace std; void fun(int b[],int t){ for(int j=0;j<t;j++){ for(int i=0;i<t;i++){ if(b[i]!=0&&b[i+1]==0){ b[i+1]=b[i]; b[i]=0; } } } } int main(){ int n;cin>>n; while(n--){ int a[4]={0},j=3,i=2; scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3]); for(;j>0;j--){ if(a[j]==0){ j--;i--; } if(a[j]==a[i]){ a[j]+=a[i]; a[i]=0;i=j-2; } else i--; } fun(a,4); cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<endl; } return 0; } /* Main.cc: In function 'int main()': Main.cc:13:8: error: 'cin' was not declared in this scope int n;cin>>n; ^ Main.cc:16:46: error: 'scanf' was not declared in this scope scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3]); ^ Main.cc:28:3: error: 'cout' was not declared in this scope cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<endl; ^ Main.cc:28:48: error: 'endl' was not declared in this scope cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<a[3]<<endl; ^ */ |
Double click to view unformatted code.