SOURCE Blog Address http://onlywish.me
Weigh the weight with the balance
With 1,3,9,27,81 weights.
Enter a number within 121. Find the Weighing method:
such as: input 10 display 9+1;
Input 7 display 9-3+1;
Here are the answers (self-written, non-standard):
#include <stdio.h>#include<math.h>intsum =0; intarray[5] = {1,3,9, -,Bayi}; intcount[5] = {1,4, -, +,121}; Charjo[2][2] ={'+ ', '-'}, {'-', ' +'}};voidDigui (int,int);voidMain () {intnum;//scanf ("%d", &num); for(inti =1; I <122; i++) {printf ("%d =", i); Digui (i,0); }}voidDigui (intNumintj) { for(inti =0; i<5; i++) if(Num <= count[i]) Break;//positioning if(Num >Array[i]) {printf ("%d%c", array[i],jo[j][0]); if(J = =1) J = (j+1)%2; Digui (fabs (Num-Array[i]), j); } if(Num <Array[i]) {printf ("%d%c", array[i],jo[j][1]); if(J = =0) J = (j+1)%2; Digui (fabs (Num-Array[i]), j); } if(num = =Array[i]) {printf ("%d\n", Array[i]); return; }
Weigh weight of balance weight