HDU 1597 find the nth digit
来源:互联网 发布:巨灵新闻数据库 编辑:程序博客网 时间:2024/05/16 18:48
find the nth digit
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5666 Accepted Submission(s): 1606
Problem Description
假设:
S1 = 1
S2 = 12
S3 = 123
S4 = 1234
.........
S9 = 123456789
S10 = 1234567891
S11 = 12345678912
............
S18 = 123456789123456789
..................
现在我们把所有的串连接起来
S = 1121231234.......123456789123456789112345678912.........
那么你能告诉我在S串中的第N个数字是多少吗?
S1 = 1
S2 = 12
S3 = 123
S4 = 1234
.........
S9 = 123456789
S10 = 1234567891
S11 = 12345678912
............
S18 = 123456789123456789
..................
现在我们把所有的串连接起来
S = 1121231234.......123456789123456789112345678912.........
那么你能告诉我在S串中的第N个数字是多少吗?
Input
输入首先是一个数字K,代表有K次询问。
接下来的K行每行有一个整数N(1 <= N < 2^31)。
接下来的K行每行有一个整数N(1 <= N < 2^31)。
Output
对于每个N,输出S中第N个对应的数字.
Sample Input
61234510
Sample Output
112124
思路:先要知道n是在哪一层,然后找到具体的位置上所对应的那个数就行了。每一层是数字都是到9然后循环的。
AC代码:
#include<iostream>using namespace std;int main(){int k,n,i,s,m,a[9]={9,1,2,3,4,5,6,7,8};while(scanf("%d",&k)!=EOF){while(k--){scanf("%d",&n);s=0; for(i=1;s<n;i++)s+=i;s=s-i;m=n-s-1;printf("%d\n",a[m%9]);}}return 0;}
- hdu Problem - 1597 find the nth digit
- HDU 1597 find the nth digit
- hdu 1597 find the nth digit
- Hdu 1597 find the nth digit
- hdu 1597 find the nth digit
- hdu 1597 find the nth digit
- HDU 1597 find the nth digit
- HDU 1597:find the nth digit
- hdu 1597 find the nth digit
- hdu find the nth digit(1597)
- hdu 1597 find the nth digit
- hdu 1597 数学题 find the nth digit
- HDU 1597 find the nth digit
- HDU 1597 find the nth digit
- HDU 1597 find the nth digit 水题
- HDU 1597:find the nth digit【规律】
- HDU 1597 find the nth digit
- HDU 1597 find the nth digit
- mysql
- 批处理,%~d0 cd %~dp0 代表什么意思
- HP ALM 使用经验
- Lapka:iPhone专用的多功能环境监测器
- Application does not specify an API level requirement!
- HDU 1597 find the nth digit
- hibernate 联合查询fetch
- 离散Hilbert变换的一些说明
- linux 开发程序过程 vim
- 寻找丑数
- Xen Cloud Platform 系列:XenCenter 安装
- VS2010的智能提示没有了的可能原因
- linux chkconfig 使用说明
- C无符号数和有符号数探讨