| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:将大牛的修改了下,加了点注释,这样可能好理解点In Reply To:将大牛的修改了下,加了点注释,这样可能好理解点 Posted by:fbixiaozc135 at 2007-08-08 15:36:25 > #include <string.h>
> #include <stdio.h>
>
> int main()
> {
> int a[5]={0, 45, 9045, 1395495, 189414495};
> int b[5]={0, 9, 189, 2889, 38889};
> int c[5]={0, 10, 100, 1000, 10000};
> unsigned long i,j,k,n,t;
> scanf("%d",&t);
> while(t--)
> {
> scanf("%d",&n);
> for ( i = 1; i < 5; i++)
> if (n <= a[i]) break; //所在的行数为 i位数
> n -= a[i - 1];
> for (k = 0, j = 1; k < n; j++)
> k = b[i - 1] * j + i * j * (j + 1) / 2; //等差数列求和公式,找到具体的区间位置
> --j;
> n = n - b[i - 1] * (j - 1) - i * j * (j - 1) / 2; //在该数中寻找最终的位置
> for(i = 1; i < 5; i++)
> if (n <= b[i]) break; //通过位置来确定最终这个数是几位数
> if (i == 1) //如果是1位数,直接输出
> printf("%d\n",n);
> else //求得在该数的一排中 最后更新了的序号n对应的数字
> {
> n -= b[i-1];
> /*要找的数最终在的位置的真正的数比如11的位置是4,这里k就等于11 */
> k = (n-1) / i + c[i-1];
> char str[10];
> sprintf(str,"%d",k); //将数字转换成字符串
> n -= (n - 1) / i * i;
> printf("%c\n",str[n - 1]);
> }
> }
> return 0;
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator