POJ 1019

来源:互联网 发布:新媒体营销的数据 编辑:程序博客网 时间:2024/05/16 15:20
/* * poj_1019.c * accepted? */#include <stdio.h>#include <math.h> /* pow, log10 */static int poj_1019 (int);int main (int argc, char ** argv){    int i,n;    int k,r;    scanf ("%d", &n);    for (k=0; k<n; k++){        scanf ("%d",&i);        r = poj_1019 (i);        printf ("%d\n", r);    }}unsigned int a[31270];unsigned int s[31270];static int poj_1019 (int n){    int i;    int length = 0;    int pos;    a[1] = 1;    s[1] = 1;    for (i=2; i<31270; i++){        a[i] = a[i-1] + (int)log10((double)i)+1;        s[i] = s[i-1] + a[i];    }        for (i=1; s[i]<n; i++){         ;    }    pos = n - s[i-1];    for (i=1; length < pos; i++){         length += (int)log10((double)i) + 1;    }    return (i-1)/ (int)pow((double)10, length - pos)%10;/*为什么不是 (i-1)%10 */}

参考:http://www.slyar.com/blog/poj-1019-cpp.html

还没有想清楚return语句的含义

原创粉丝点击