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 ...
随机推荐
- Python web自动化测试框架搭建(功能&接口)——unittest介绍
Python UnitTest测试框架介绍 1) TestCase:所有测试用例类继承的基本类, TestCase的实例就是测试用例 2) TestSuite:测试套件 ...
- Selenium WebDriver Log4j打印执行日志
在自动化测试脚本的执行过程中,使用log4j在日志文件中打印执行日志,用于监控和后续调试脚本. Log4j.xml 文件 <log4j:configuration xmlns:log4j=&qu ...
- linux使用pigz多线程压缩
因为tar zip是单线程的压缩,压缩起来很慢,这个使用使用pigz工具辅助就会使用多线程了. 安装 sudo apt install pigz 压缩 tar cvf - test.txt | pig ...
- 【OpenGL】---认识CubeTexture
一.OpenGL Cube Texture 立方体纹理 立方体纹理是一种特殊的纹理技术,他用6幅二维贴图构成一个以原点为中心的纹理立方体.对于每个片段,纹理坐标(s,t,r)被当做三维向量看待,每个纹 ...
- PTA 1154 Vertex Coloring
题目链接:1154 Vertex Coloring A proper vertex coloring is a labeling of the graph's vertices with colors ...
- iintellij IDEA运行环境使用教程
1.官网:https://www.jetbrains.com 链接: https://pan.baidu.com/s/10QKLn1bGEW9W0pXEp6WR1A 提取码: vt2b 看官觉得有用留 ...
- 06:(h5*)Vue第六天
目录 1:iView 2: element 3: vuex 正文 1:i-view 1:装包 npm install view-design --save 2:导包 import ViewUI f ...
- python可变数据类型和不可变数据类型
1.可变数据类型:在id不变的情况下,value可改变(列表和字典是可变类型,但是字典中的key值必须是不可变类型) 2.不可变数据类型:value改变,id也跟着改变.(数字,字符串,布尔类型,都是 ...
- 链接层-UDP
五大特点:无连接,不可靠,面向报文传输,没有拥塞控制,首部开销小
- lucene版本升级到4.6.0以上之后使用ik分词器遇到的问题
在将lucene core版本从4.5.1升级到4.7.0后,如下代码使用ik分词器报错 IKAnalyzer analyzer = new IKAnalyzer(true); StringReade ...