Digit
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的更多相关文章
- [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 ...
- [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 ...
- [Leetcode] Number of Digit Ones
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...
- 【Codeforces715C&716E】Digit Tree 数学 + 点分治
C. Digit Tree time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ...
- kaggle实战记录 =>Digit Recognizer
date:2016-09-13 今天开始注册了kaggle,从digit recognizer开始学习, 由于是第一个案例对于整个流程目前我还不够了解,首先了解大神是怎么运行怎么构思,然后模仿.这样的 ...
- [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_ ...
- 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 ...
- POJ3187Backward Digit Sums[杨辉三角]
Backward Digit Sums Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6350 Accepted: 36 ...
- Number of Digit One
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...
- 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 ...
随机推荐
- CodeIgniter 技巧 - 通过 Composer 安装 CodeIgniter 框架并安装依赖包
PHP 项目中,通过 Composer 来管理各种依赖包,类似 Java 中的 Maven,或 Node 中的 npm.CodeIgniter 框架要想通过 Composer 自动加载包也很简单,步骤 ...
- Bootstrap 学习笔记9 标签页和工具提示插件
<ul class="nav nav-tabs"> <li class="active"><a href="#html5 ...
- C#静态变量总结
1.初始化 全局static变量的初始化在编译的时候进行,并且只初始化一次 . 函数static变量在函数中有效,第一次进入函数初始化.以后进入函数将沿用上一次的值. 2.生命期 全局static变 ...
- php用什么软件编程
准备好好学习学习PHP了吗?那么你首先应该考虑用什么开发工具(IDE).市面上有很多这类工具,收费的有,免费的也有,选择起来并不轻松. 如果你说PHP编程用基础的文本编辑软件就可以了,比如用记事本.是 ...
- 《JAVA设计模式》之命令模式(Command)
在阎宏博士的<JAVA与模式>一书中开头是这样描述命令(Command)模式的: 命令模式属于对象的行为模式.命令模式又称为行动(Action)模式或交易(Transaction)模式. ...
- debain8 安装mysql8
一.下载apt源 https://dev.mysql.com/downloads/repo/apt/ 二.更新apt sudo apt-get update 三.安装mysql sudo apt-ge ...
- IDEA 光标显示注释
- 转义BABEL的POLYFILL和RUNTIME的区别
babel-polyfill 使用场景 Babel 默认只转换新的 JavaScript 语法,而不转换新的 API.例如,Iterator.Generator.Set.Maps.Proxy.Refl ...
- python学习第十四天字典的del(),pop().popitem(),clear()删除方法
字典的每个键值 key=>value 数据类型,字典的key是唯一的,Value可以一样 names={'玖乐公司网址':‘www.96net.com.cn’,"电池网":' ...
- Windows组决策
https://blog.csdn.net/wangjunjun2008/article/details/82426587