Home > Back-end >  To solve the programming topics
To solve the programming topics

Time:10-23

Have bosses teach beginners how to use c + + write this program (note: to list all combination)

CodePudding user response:

The building Lord, the number of each ball is unknown?

CodePudding user response:

 # include "stdafx. H" 

#include

#include

using namespace std;

Int main ()
{
Enum color {red, yellow, blue, white, black};//declare enumerated type color

Color pri.//color types of variables pri

Int I, j, k, n=0, loop;//n is the total different color combinations of

For (I=red; i<=black; I++)//when I for a certain color
{
For (j=red; J<=black; J++)//when the j is a color
{
If (I.=j)//if the color of the ball in the first two different
{
For (k=red; k<=black; K++)//only the first two balls of different colors, just need to check the color of the ball in the third
{
If (k!=i& & k!=j)//the color of the ball in the three different
{
N=n + 1;//that the cumulative value of n + 1

Cout
For (loop=1; Loop<=3; Loop++)//successively to three ball processing
{
The switch (loop)//the value of the loop for 1, 2, 3
{
Case 1: pri=color (I); break;//color is casts (I), the pri has a value of I

Case 2: pri=color (j); break;//j

Case 3: pri=color (k); break;//k

Default: break;
}

Switch (pri)//judge pri values, output the corresponding color
{
Case red: cout
Case yellow: cout
Case blue: cout
Case white: cout
Case black: cout
Default: break;
}
}

Cout}
}
}
}
}

Cout<" Total: "& lt;
return 0;
}

CodePudding user response:

The title is wrong! Such as red balls if only less than 3 and greater than or equal to three, the answer must be different, so the problem must be clear

CodePudding user response:

reference 1st floor qq_46311062 response:
the building, the number of each ball is unknown?

Yes, that's to exhaustion

CodePudding user response:

reference liups reply: 3/f
title wrong! Such as red balls if only less than 3 and greater than or equal to three, the answer must be different, so this kind of problem must be clearly

Ha ha ha makes sense just to ignore the situation teacher of the topic
  • Related