poj1019

有一个序列
1
12
123
1234
.....
........
...........
12345678910
................................
求第n个数字是什么,数字有点大- -
直接A
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;

#define maxn 200000

long long a[maxn];

int main()
{
    long long i, k=10, t=1, T;

    for(i=1; i<maxn; i++)
    {
        if(k == i)
        {
            k *= 10;
            t++;
        }
        a[i] = a[i-1] + t;
    }
    cin >> T;

    while(T--)
    {
        long long n;
        char s[20];

        cin >> n;

        for(i=1; a[i]<n; i++)
            n -= a[i];

        k=10,t=1;
        for(i=1; ; i++)
        {
            if(k == i)
            {
                k *= 10;
                t++;
            }

            if(n-t > 0)
                n -= t;
            else
                break;
        }
        sprintf(s, "%d", i);
        cout << s[n-1] <<endl;
    }

    return 0;

} 

原文地址:https://www.cnblogs.com/liuxin13/p/4383930.html