Ytuoj-c language Experiment-permutation

Source: Internet
Author: User

The description has 4 distinct numbers and outputs an arrangement of three distinct digits. Input4 an integer. Output all permutations. Sample Input
1 2 3 4
Sample Output
1 2 31 3 22 1 32 3 13 1 23 2 11 2 41 4 22 1 42 4 14 1 24 2 11 3 41 4 33 1 43 4 14 1 34 3 12 3 42 4 33 2 43 4 24 2 34 3 2
HINT

Source

Zjgsu

The code is as follows:

#include <stdio.h>int i,j,k,a[3],b[3],c[3];void Sort (int e[]) {for    (i=0; i<3; i++)        a[i]=b[i]=c[i]=e[ I];    For (i=0, i<3; i++)    {for        (j=0; j<3; J + +) {for            (k=0; k<3; k++)            {                if (a[i]==b[j]| | a[i]==c[k]| | B[J]==C[K])                    continue;                else                    printf ("%d% d%d\n", A[i],b[j],c[k]);}}}    int main () {    int i, d[4],e[3];    for (i=0; i<4; i++)        scanf ("%d", d+i);    E[0]=D[0],E[1]=D[1],E[2]=D[2];    Sort (e);    E[0]=D[0],E[1]=D[1],E[2]=D[3];    Sort (e);    E[0]=D[0],E[1]=D[2],E[2]=D[3];    Sort (e);    E[0]=D[1],E[1]=D[2],E[2]=D[3];    Sort (e);    return 0;}


Operation Result:

Learning experience:

Recently trying to use C language to do the problem, but still can not get rid of the thick C + +, often because with some keywords in C + + error.

In fact, this problem is not thought at first, the first reaction is the enumeration, the result that only applies to the case of 1,2,3,4. Then thought of using multiple arrays to save, can be executed perfectly, but still wrong, it actually asked the order,

Thus further complications, which were divided four times at a time. Finally, it's AC.

Ytuoj-c language Experiment-permutation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.