#include<stdio.h> int main() { int a; scanf("%d",&a); int b[4]; for(int i = 0;i<a;i++) { for(int j=0;j<4;j++) { scanf("%d",&b[j]); } for(int j=0;j<4;j++) { for(int k=3;k>j;k--) if(b[k]==0) { b[k]=b[k-1]; b[k-1]=0; } } for(int j=3;j>0;j--) { if(b[j]==b[j-1]&&b[j]!=0) { b[j]+=b[j]; b[j-1]=0; } } for(int j=0;j<4;j++) { for(int k=3;k>j;k--) if(b[k]==0) { b[k]=b[k-1]; b[k-1]=0; } } for(int j=0;j<4;j++) { printf("%d ",b[j]); } } return 0; } |
Double click to view unformatted code.