{{{~cpp #include #include using namespace std; int testcase, number, i, counting; int input[10], temp[10], carry[10]; int tempNum; bool isPanline; void getReverseAndAdd() { counting=0; while(!isPanline) { isPanline=true; for(i=0; i<10; i++) carry[i]=0; for(i=9; i>=number; i--) { if(input[i]+input[number-i+9]+carry[i]>9) { carry[i-1]=1; temp[i] = (input[i]+input[number-i+9]+carry[i])%10; } else temp[i] = input[i]+input[number-i+9]+carry[i]; } if(carry[i]==1) { temp[i]=1; number--; } for(i=0; i<10; i++) input[i] = temp[i]; counting++; for(i=0; i<10; i++) if(carry[i]==1) isPanline=false; } cout << counting << " "; for(i=number; i<10; i++) cout << input[i]; cout << endl; } int main() { cin >> testcase; while(testcase--) { cin >> tempNum; number=9; for(i=0; i<10; i++) { if(i==0) input[number] = tempNum%10; else { if((int)(tempNum/pow(10, i))!=0) { number--; input[number]=(int)(tempNum/pow(10, i))%10; } } } isPanline = false; getReverseAndAdd(); } return 0; } }}}