Exhaustive method - Exercises

1, the reverse order to solve a number of the array:

int Reverse(int a[],int n){
    int i,j,count;
    for(i=0;i<n-1;i++)
    for(j=i+1;j<n;j++)
    if(a[i]<a[j]) 
    count++;
    return count; 
} 

2, a group of a group of chickens and rabbits, they have the same number only, are three-digit number of feet, and the two three-digit numbers are 0,1,2,3,4,5. The number of chickens and rabbits by seeking exhaustive method is the number? Their number is the number of feet?

void chickenAndRabbit(){
   int a,b,c,d,e,f,chicken,rabbit;
   for(a=2;a<=6;a++)
    for(b=1;b<=6;b++)
     for(c=1;c<=6;c++)
     
      for(d=2;d<=6;d++)
       for(e=1;e<=6;e++){
           f=21-a-b-c-d-e;
           if(a*b*c*d*e*f==720){
              chicken=(a*100+b*10+c-111)/2;
              rabbit=(d*100+e*10+f-111)/4;
              
              if(chicken==rabbit){
              printf("%d\n",chicken);
              printf("%d",rabbit);
              }
             
              }
       }
}

Because if the number of columns contain the number zero, then the product will be zero, and therefore put all the numbers plus one, plus one each equivalent to all the three-digit, that is to say plus 111, so subtract .

3, there is a three-digit number, larger than the single-digit hundreds digit, one hundred large numbers off than ten digits, and the digits equal to the sum of the digits of the product of multiplying.

#include <stdio.h>
 void NUM () {
       int GE, Shi, Bai;
       for (Shi = 0 ; Shi <= . 7 ; Shi ++ )
        for (Bai = Shi + . 1 ; Bai <= . 8 ; Bai ++ )
         for (GE = Bai + . 1 ; GE <= . 9 ; GE ++ )
           IF ((GE + Shi + Bai) == GE * Shi * Bai) {
            int NUM = Bai * 100 + Shi * 10 + GE; 
           the printf ( " % D " , NUM) ;     
          } 
} 
int main(){
    num();
}

operation result:

 

 The brute-force method of solving typical problems: select statement loop +

 

 

Open-minded: Do not unpleasant mere trifles upset, despair. - Franklin

Guess you like

Origin www.cnblogs.com/zhai1997/p/12077625.html