Cantor的数表

来源:互联网 发布:网络摄像头一体机 编辑:程序博客网 时间:2024/06/10 06:28
#include <stdio.h>
#include <stdlib.h>
#include <string.h>



int main()
{
    int n,x=1,y=1,count=1;
    scanf("%d",&n);
    for(;;)

    {

        //往左走

        if(count<n)
        {
            y++;
            count++;

        }

         //往左下方走

        while(y>1 && count<n)
        {
            x++;
            y--;
            count++;

        }

        //往下走

        if(count<n)
        {
            x++;
            count++;

        }

        //往右上方走

        while(x>1 && count<n)
        {
            x--;
            y++;
            count++;
        }
        if(count==n)
            break;
    }
    printf("%d/%d",x,y);

    return 0;
}

0 0
原创粉丝点击