Click the Twitter icon to follow our tweets and
know more about us.

AMAGRAM

class amagram
{
    public static void main(String nm)
    {
        int l=nm.length(),k,s=1;
        for(k=1;k<=l;k++)
        s=s*10+(l-1);
        for(int i=(int)(Math.pow(10,l));i<s;i++)
        {
            k=0;String b="";
            for(int j=0;j<l;j++)
            {
                int p=i;b="";
                while(p>1)
                {
                    int d=p%10;
                    p/=10;
                    if(d<l)
                    b=nm.charAt(d)+b;
                    if(d==j)
                    k++;
                }
                if(k==1)
                k=0;
            }
            if(k==0 && b.length()==l)
            System.out.println(b);
        }
    }
}

Comments (0)

Post a Comment