【C实现】P1014 [NOIP1999 普及组] Cantor 表

#include <stdio.h>
int main() {
    int given;
    int i = 1, is_odd = 0, fenzi = 0, fenmu = 0, sum;
    scanf("%d", &given);
    while(given > i){
        given -= i;
        i++;
    }
    if (given == 0){
        i--;

    }
    sum = i+1;
    if (i%2!=0){
        is_odd =1;
    }
    if (is_odd == 1){
        fenzi = sum - given;
        fenmu = sum - fenzi;
    }
    else{
        fenmu = given;
        fenzi = sum - fenmu;
    }
    printf("%d/%d\n", fenzi, fenmu);
    return 0;
}

上一篇:P1014 Cantor表


下一篇:【找规律】P1014 Cantor表