Click here to Skip to main content
15,936,014 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is the question what I translated. My translate is bad hope you will understand.
Show every triplet(x,y,z) where x <= A, y <= B, z <= C (0 <= A, B, C <= 20) and show x,y and z small to large.
input files first line will give test case's number (t <= 20). After this on the number of line T there are theree number A ,B,C.

For Every case begainning the case number print "Case X :" Where case is 1 to T. Then print every tripolet small to large. Tripolet's are arranged by lexicographical sequence .

N.B : Lexicographic sequence - a tripolet (a1,b1,c1) another tripolet (a2,b2,c2) will be smaller by Lexicographic sequence and if the condition is true what given here : (i) a1 < a2 (ii) a1 = a2 and b1 < b2 (iii) a1 = a2 and b1 = b2 and c1 < c2 .
Input :
3 //Number of line (Case/ T)
1 1 2
3 2 3
4 4 4

Case 1:
0 1 2
Case 2:
0 1 2
0 1 3
0 2 3
1 2 3
Case 3:
0 1 2
0 1 3
0 1 4
0 2 3
0 2 4
0 3 4
1 2 3
1 2 4
1 3 4
2 3 4 

What I have tried:

int main()
    int T, i, j, A, B, C, temp = 0;
    while(T--) {
        scanf("%d %d %d",&A,&B,&C);
        // bubble short for high to low 
        for(i = 0;i < 3;i++) {
            if(A > B) {
                temp = A;
                A = B;
                B = temp;
            else if (A > C) {
                temp = A;
                A = C;
                C = temp;
            else if(B > C) {
                temp = B;
                B = C;
                C = temp;

I can't figure out the algorithm. but I tried some.
First, I sequence small to large by bubble shoot. Then I can't understand what I should (second step - lexicographic sequence). Even I don't know, is it wright way? or not?
Updated 19-Oct-22 14:35pm

1 solution

I have no idea why you are doing a sort in this. I would approach the problem as a three digit counter and each digit can range from zero to the value that was input. When a digit is incremented such that it exceeds its limit then it is zeroed and the next digit is incremented. This is just like how normal base ten counting works except it has a limit of 9 on each digit. To maintain the counter, I would use an array of three integers. Start with all three set to zero and then start incrementing each one and evaluate the rules you were given. You can map the "a" digit to slot 0, "b" to slot 1, and "c" to slot 2 if you want to.

Also, I would write the set of input data to a file and use the redirection operator to set your programs stdin to be the file. That would be something like this on the command line :
YourProgram < InputData.txt
Then you can have multiple input files to select from and try lots of possibilities very quickly.
Share this answer
CPallini 20-Oct-22 7:21am    
Rick York 20-Oct-22 10:58am    
Thank you sir.
Lara Thomas 20-Oct-22 16:27pm    
Are you implying something like that?
Rick York 20-Oct-22 17:11pm    
Not exactly but it might work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900