Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7593007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:03:27+00:00 2026-05-30T21:03:27+00:00

let’s say , a course with 8 participans, i must output the first 3

  • 0

let’s say , a course with 8 participans, i must output the first 3 places in all possible ways.
ex :

123
124
125
126
127
128
213
so on..

I know there is next_permutation algorithm but it returns all the possible permuations with all the numbers (from 1 through 8), but i need first 3 places with all the participans
ex:

1  2  3  4  5  6  7  8  
1  2  3  4  5  6  8  7
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:03:28+00:00Added an answer on May 30, 2026 at 9:03 pm

    This program produces the output you are looking for, not necessarily in the order you expect. If you want it in a particular order, you may need to capture the output and sort it. To see it run, look here.

    #include <algorithm>
    #include <iostream>
    
    template <typename Iterator>
    inline bool next_combination(Iterator first,
      Iterator k,
      Iterator last);
    
    int main () {
      int array[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
      do {
        do {
           std::cout << array[0] << array[1] << array[2] << "\n";
        } while(std::next_permutation(array, array+3));
      } while(next_combination(array,array+3,array+8));
    }
    
    template <typename Iterator>
    inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
    {
       /* Credits: Thomas Draper */
       // http://stackoverflow.com/a/5097100/8747
       if ((first == last) || (first == k) || (last == k))
          return false;
       Iterator itr1 = first;
       Iterator itr2 = last;
       ++itr1;
       if (last == itr1)
          return false;
       itr1 = last;
       --itr1;
       itr1 = k;
       --itr2;
       while (first != itr1)
       {
          if (*--itr1 < *itr2)
          {
             Iterator j = k;
             while (!(*itr1 < *j)) ++j;
             std::iter_swap(itr1,j);
             ++itr1;
             ++j;
             itr2 = k;
             std::rotate(itr1,j,last);
             while (last != j)
             {
                ++j;
                ++itr2;
             }
             std::rotate(k,itr2,last);
             return true;
          }
       }
       std::rotate(first,k,last);
       return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have an facebook application running using the JS SDK. First user
Let's say, if I need to assign an id to element with first name,
Let's say I have multiple requirements for a password. The first is that the
Let's say I query for http://images.google.com.sg/images?q=sky&imgcolor=black and I get all the black color sky,
Let's say you create a wizard in an HTML form. One button goes back,
Let's say I'm building a data access layer for an application. Typically I have
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say I have a drive such as C:\ , and I want to
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.