This question is quite interesting. I don't know how to classify it into Gaussian. It should be an enumeration.
The idea is very good, not to mention, look at the code
C, which array is prone to initialization errors?
The final output is a bit confusing, but you may not need to pay special attention to the last space.
#include <cstdio>#include <cstring>#include <iostream>#include <cstdlib>using namespace std;int c[10][10]={{0,0,0,0,0,0,0,0,0,0},{0,1,1,0,1,1,0,0,0,0},{0,1,1,1,0,0,0,0,0,0},{0,0,1,1,0,1,1,0,0,0},{0,1,0,0,1,0,0,1,0,0},{0,0,1,0,1,1,1,0,1,0},{0,0,0,1,0,0,1,0,0,1},{0,0,0,0,1,1,0,1,1,0},{0,0,0,0,0,0,0,1,1,1},{0,0,0,0,0,1,1,0,1,1}};void copy(int* tmp,int* num){for(int i=1;i<=9;i++)tmp[i]=num[i];}void add(int* tmp,int i,int ti){for(int ii=1;ii<=9;ii++){tmp[ii]+=c[i][ii]*ti;tmp[ii]%=4;}}bool check(int* tmp){for(int i=1;i<=9;i++){if(tmp[i]!=0)return false;}return true;}int sum(int* t){int s=0;for(int i=1;i<=9;i++)s+=t[i];return s;}int num[10];int tmp[10];int t[10];int ans[10];int minn=9999999;int main(){for(int i=1;i<=9;i++)cin>>num[i];for(t[1]=0;t[1]<=3;t[1]++)for(t[2]=0;t[2]<=3;t[2]++)for(t[3]=0;t[3]<=3;t[3]++)for(t[4]=0;t[4]<=3;t[4]++)for(t[5]=0;t[5]<=3;t[5]++)for(t[6]=0;t[6]<=3;t[6]++)for(t[7]=0;t[7]<=3;t[7]++)for(t[8]=0;t[8]<=3;t[8]++)for(t[9]=0;t[9]<=3;t[9]++){copy(tmp,num);for(int i=1;i<=9;i++)add(tmp,i,t[i]);if(!check(tmp))continue;else if(sum(t)<minn){minn=sum(tmp);copy(ans,t);}}int last=0;for(int i=1;i<=9;i++){if(ans[i])last=i;}for(int i=1;i<last;i++){for(int k=1;k<=ans[i];k++){cout<<i<<' ';}}for(int k=1;k<ans[last];k++)cout<<last<<' ';cout<<last<<'\n';return 0;}