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. applicationContext.xml无错有红叉,Error occured processing XML 'Provider org.apache.xerces.parsers.解决方案

    applicationContext.xml无错有红叉,网上讲的取消xml验证的方法没用... 甚至我的myeclipse10连windows-->perferences-->myecli ...

  2. 第1 章 mysql数据库之简单的DDL和DML sql语句

    一.SQL 介绍 1.什么是sql? SQL,英文全称(Structured Query Language),中文是结构化查询语言,它是一种对关系数据库中数据进行定义和操作的语言方法,是大多数关系数据 ...

  3. JS对象—对象总结(创建、属性、方法)

    1.创建对象Object 1.1 字面量的方式创建 1.2  new Object() 1.3 构造函数创建 1.4 工厂模式 1.5 Object.create()  ES5新增方法 Object. ...

  4. SQL查询返回去除重复数据的结果集

    方法一: select * from  tablename  where  id   in   (select  id  from  tablename   group  by  id   havin ...

  5. #C语言l作业04

    这个作业属于哪个课程** C语言程序设计ll 这个作业的要求 (https://edu.cnblogs.com/campus/zswxy/SE2019-4/homework/9776) 我在这个课程的 ...

  6. linux下shell显示git当前分支

    function git-branch-name { git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3 } functio ...

  7. sed删除注释行和空行

    典型需求: 删除nginx.conf文件中注释行和空行 sed -i '/^#/d;/^$/d' nginx.conf 删除一个或多个空格加 # 号的行 sed -i '/[:blank:]*#/d' ...

  8. Java-多线程第三篇3种创建的线程方式、线程的生命周期、线程控制、线程同步、线程通信

    1.Java使用Thread类代表线程.     所有的线程对象必须是Thread类或其子类的实例. 当线程继承Thread类时,直接使用this即可获取当前线程,Thread对象的getName() ...

  9. Struts2之上传

    单文件上传 上传页面 <%@ page language="java" contentType="text/html; charset=UTF-8" pa ...

  10. elasticsearch 基础 —— Get API

    Get API get API允许根据其id从索引中获取指定类型的JSON文档.以下示例从名为twitter的索引获取JSON文档,该索引类型名为_doc,id值为0: GET twitter/_do ...