#include <stdio.h>

int main() {
    int a[1000],z[1000],x[10000]={};
    int m,n,o,p,q,r,t=0;
    scanf("%d %d %d %d",&m,&n,&o,&p);
    z[0]=m*1000+n*100+o*10+p;
    z[1]=n*1000+o*100+p*10+m;
    z[2]=o*1000+p*100+m*10+n;
    z[3]=p*1000+m*100+n*10+o;
    int k=0;
    for(int i=0;i<4;i++)
    {
        for(int j=i;j<4;j++)
        {
            if(z[i]>z[j])
            {
                k=z[i];
                z[i]=z[j];
                z[j]=k;
                }
            }
        }
    q=z[0];
    char c[1000];
    c[0]=1,c[1]=1,c[2]=1,c[3]=1;
    while(r<q)
    {
        for(int i=0;i<4;i++)
        {
            a[i]=c[i]-'0';
        }
        z[0]=a[0]*1000+a[1]*100+a[2]*10+a[3];
        z[1]=a[1]*1000+a[2]*100+a[3]*10+a[0];
        z[2]=a[2]*1000+a[3]*100+a[0]*10+a[1];
        z[3]=a[3]*1000+a[0]*100+a[1]*10+a[2];
        k=0;
        for(int i=0;i<4;i++)
        {
            for(int j=i;j<4;j++)
            {
                if(z[i]>z[j])
                {
                    k=z[i];
                    z[i]=z[j];
                    z[j]=k;
                }
            }
        }
        x[z[0]]++;
        c[3]++;
        if(c[3]>9)
        {
            c[3]=1;
            c[2]++;
        }
        if(c[2]>9)
        {
            c[2]=1;
            c[1]++;
        }
        if(c[1]>9)
        {
            c[1]=1;
            c[0]++;
        }
        r=c[0]*1000+c[1]*100+c[2]*10+c[3];
        if(x[z[0]]==1) t++;
    }
    printf("%d",t+1);
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: