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. js面向对象程序设计之构造函数

    再上一篇的开头说了创建对象的两种方式,一种是Object构造函数的方式,一种是对象字面量的方法.但这些方式创建多个对象的时候都会产生大量的重复代码.经过技术的进步也演化出来许多的创建对象的模式.本章会 ...

  2. Vue自定义事件:触发自定义事件

    一 项目结构 二 子组件(Mongo.vue) <template> <button @click="eat">按钮</button> < ...

  3. 让 Visio 2003/2007 同时开多个独立窗口

    1. 打开 Visio 2003/2007 2. 点击菜单[工具] -> [选项]: 3. 在弹出的“选项” 对话框中选择“高级”选项页: 4. 去掉“在同一窗口中打开每一 ShapeSheet ...

  4. python pip报错pip._ vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.

    AttributeError: module 'pip' has no attribute 'main报错 找到安装目录下 helpers/packaging_tool.py文件,找到如下代码: de ...

  5. jvm(4) 对象创建

    1.对象的创建过程: 1.new 类名 2.根据new的参数在常量池中定位一个类的符号的引用. 3.如果没找到这个符号的引用,说明类还没有被加载.则进行类的加载,解析和初始化 4.虚拟机为对象分配内存 ...

  6. 玩爆你的手机联系人--T9搜索(一)

         自己研究了好几天联系人的T9搜索算法, 先分享出来给大家看看. 欢迎不吝赐教.假设有大神有更好的T9搜索算法, 那更好啊,大家一起研究研究,谢谢. 第一部分是比較简单的获取手机联系人. 获取 ...

  7. 【freemarker】渲染列表一系列操作

    数据模型: public class AddressVo implements Serializable { private static final long serialVersionUID = ...

  8. JavaScript——实现继承的几种方式

    实现继承的6中方法: 借用构造函数 组合继承 原型式继承 寄生式继承 寄生组合式继承 拷贝继承 1. 借用构造函数 在子类型构造函数的内部调用超类构造函数.通过使用apply()和call()方法在新 ...

  9. K8S命令大总结

    一.k8s-kubectl命令大全 Kubectl命令行管理对象类型 命令 描述 基础命令 create 通过文件名或标准输入创建资源. expose 将一个资源公开为一个新的Kubernetes服务 ...

  10. Codeforces Round #392 (Div. 2) - B

    题目链接:http://codeforces.com/contest/758/problem/B 题意:给定n个点灯的情况,灯只有四种颜色RBGY,然后如果某个灯坏了则用'!'表示,现在要求将坏的灯( ...