Digit

Accepted : 85   Submit : 308
Time Limit : 1000 MS   Memory Limit : 65536 KB 

题目描述

我们把十进制整数依次写成一个字符串,123456789101112…请问第n位数码是多少?

输入

第一行是一个整数T(T≤10000),表示样例的个数。 每行输入一个整数n(1≤n≤788888899)。

输出

每行输出一个样例的结果。

样例输入

2
1
788888899

样例输出

1
1 理解不了什么意思,先存着= =|| 理解之后回来看看^_^ #include <cstdio>
#include <cstring>
#include <math.h>
#include <iostream>
#include <algorithm> using namespace std; __int64 num[15]={0,9,99,999,9999,99999,999999,9999999,99999999,999999999,9999999999}; // 几位数,临界值
__int64 sum[15]; //几位数之前有多少数 int main ()
{
    int i, t;
    int n, m, Sum;
    sum[0] = 0;
    for (i=1; i<11; i++)
        sum[i] = sum[i-1] + (num[i]-num[i-1])*i; // 这个数是一个i位数,之前有多少数。2位数之前有9位数,3位数开始之前有189个位
    scanf ("%d", &t);
    while (t --)
    {
        scanf ("%d", &n);
        i = 1;
        while (n > sum[i])
            i ++; // n 这个数是在一个i位数中间的一个数         n -= sum[i-1]; //n变成了 这个i位数开始之后的n位数
n = n % i;  // n是这个i位数中的第n位
        Sum = num[i-1] + n / i; // num【i-1】是这个i位数开始之前的数,n/i是指第几个i位数,n是在Sum中的某一位
        m = (num[i] - num[i-1])/9; //几位数,m后就有几个零
       
        int s; //存结果
        if (n == 0)
            s = Sum % 10; // n等于0表示是这个数的最后一位
        else
        {
            Sum ++; // n大于0表示已经超过i位了,所以要加一,就是第n位在Sum+1这个数里边
            while (n --)
            {
                s = (Sum / m) % 10; // 求第n位是多少
                m /= 10;
            }
        }
        printf ("%d\n", s);
    }
    return 0;
} Do you understand?^_^||

Digit的更多相关文章

  1. [LeetCode] Nth Digit 第N位

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...

  2. [LeetCode] Number of Digit One 数字1的个数

    Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...

  3. [Leetcode] Number of Digit Ones

    Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...

  4. 【Codeforces715C&716E】Digit Tree 数学 + 点分治

    C. Digit Tree time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ...

  5. kaggle实战记录 =>Digit Recognizer

    date:2016-09-13 今天开始注册了kaggle,从digit recognizer开始学习, 由于是第一个案例对于整个流程目前我还不够了解,首先了解大神是怎么运行怎么构思,然后模仿.这样的 ...

  6. [UCSD白板题] The Last Digit of a Large Fibonacci Number

    Problem Introduction The Fibonacci numbers are defined as follows: \(F_0=0\), \(F_1=1\),and \(F_i=F_ ...

  7. Last non-zero Digit in N!(阶乘最后非0位)

    Last non-zero Digit in N! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  8. POJ3187Backward Digit Sums[杨辉三角]

    Backward Digit Sums Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6350   Accepted: 36 ...

  9. Number of Digit One

    Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...

  10. Java for LeetCode 233 Number of Digit One

    Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...

随机推荐

  1. Vue访问子组件实例或子元素

    1 尽管存在 prop 和事件,有的时候你仍可能需要在 JavaScript 里直接访问一个子组件(例如,调用子组件的方法).为了达到这个目的,你可以通过 ref 特性为这个子组件赋予一个 ID 引用 ...

  2. Game on a Tree Gym - 102392F(树上最大匹配)

    思路: 本质是求一个树上的最大匹配能否覆盖所有的点. dfs遍历,用qian[]数组记录当前节点的子树内有几个没有匹配的点(初始化为-1因为可以匹配掉一个子树中未匹配的点),pipei[]数组记录当前 ...

  3. MySQL 查询语句--------------进阶9:联合查询

    #进阶9:联合查询 /* union 联合 合并:将多条查询语句的结果合并成一个结果 语法: 查询语句1 union 查询语句2 union..... 应用场景:要查询的结果来自于多个表,且多个表没有 ...

  4. Ubuntu安装byzanz截取动态效果图

    byzanz-record主要参数选项 用法: byzanz-record [选项...] 录制您的当前桌面会话 帮助选项: -?, --help 显示帮助选项 --help-all 显示全部帮助选项 ...

  5. is_numeric漏洞总结

    将16进制数据判断为数据,这样在存入数据库后,数据库会把16进制解析成字符串,可能造成二次注入 转载: https://www.jianshu.com/p/e7cf997d6ccb

  6. Node.js实战3:加载一组模块。

    有时候,希望通过一个require来加载一个目录下的相关文件. 注:这个方法通常被用来作为组织web应用的架构技巧. 为达到这个目的,需要如此操作: 例:建立一个目录,在此目录中创建一个index.j ...

  7. (Vue)移动端点击输入框,弹出键盘,底部被顶起问题

    (Vue)移动端点击输入框,弹出键盘,底部被顶起问题:https://www.jianshu.com/p/210fbc846544 问题描述:Vue开发中,当我们相对于父视图的底部布局子控件时,需要用 ...

  8. Linux服务正常启动,Linux服务器能访问,但是外部机器不能访问

    公司用到了jenkins,就在自己虚拟机里面部署了一个jenkins.部署成功之后,在Linux虚拟机里面能正常访问,但是外部真实机却不能访问.当时的第一反应就是觉得应该是权限问题,猜测会不会是jen ...

  9. 在html模板里面加python函数(simple_tag与filter)

    自定义函数 simple_tag a. app下创建templatetags目录 b. 任意xxoo.py文件 c. 创建template对象 register d. @register.simple ...

  10. 基于GPU的图像处理平台

    基于GPU的图像处理平台 1.  (309)英伟达推Jetson TX1 GPU模块力推人工智能 1.1 产品概述 Jetson TX1 GPU模块,主要针对近年来蓬勃发展的人工智能市场,包括无人机. ...