public static void Cantor(int no)
{
int sum=0;
int i=0;
int n=0;
int mother=0;
int child=0;
for(i=0;;i++)
{
sum+=i;
n=no-sum;
if(n>0&&n<=i+1)
{
break;
}
}
if(i%2==1)
{
child=n;
mother=i+2-child;
}
else
{
mother=n;
child=i+2-mother;
}
string result=Convert.ToString(child)+"/"+Convert.ToString(mother);
Console.WriteLine(result);
}
{
int sum=0;
int i=0;
int n=0;
int mother=0;
int child=0;
for(i=0;;i++)
{
sum+=i;
n=no-sum;
if(n>0&&n<=i+1)
{
break;
}
}
if(i%2==1)
{
child=n;
mother=i+2-child;
}
else
{
mother=n;
child=i+2-mother;
}
string result=Convert.ToString(child)+"/"+Convert.ToString(mother);
Console.WriteLine(result);
}
本文介绍了一个基于康托尔配对原理的算法实现,该算法能够将一个整数映射为一对有序整数。通过一个具体的Java方法示例,展示了如何计算这一映射过程,并输出结果。
1341

被折叠的 条评论
为什么被折叠?



