find the nth digit
来源:互联网 发布:淘宝支付密码怎么修改 编辑:程序博客网 时间:2024/06/05 20:47
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10711 Accepted Submission(s): 3144
Problem Description
假设:
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)。
Output
对于每个N,输出S中第N个对应的数字.
Sample Input
6
1
2
3
4
5
10
Sample Output
1
1
2
1
2
4
Author
8600
Source
HDU 2007-Spring Programming Contest - Warm Up (1)
#include<iostream>#include<cstdio>using namespace std;long long N;int K;int main(){ scanf("%d",&K); while(K--) { long long sum=0; scanf("%I64d",&N); for(int i=0;i<N;i++){ if(sum+(i+1)>=N){// printf("%d %d\n",sum,i); if((N-sum)%9){ printf("%d\n",(N-sum)%9); } else{ printf("9\n"); } break; } sum+=i+1; // printf("%d!!!!!!!!!!!!!!!!\n",sum); } } return 0;}//sum 和 N 都应该是long long 型,开始卡在这里了,以后应注意变量类型
0 0
- find the nth digit
- find the nth digit
- find the nth digit
- find the nth digit
- find the nth digit
- find the nth digit
- find the nth digit
- find the nth digit
- find the nth digit
- HDU1597 find the nth digit
- find the nth digit(数论)
- hdu find the nth digit
- find the nth digit(math)
- HDU1597 find the nth digit
- HDOJ-1597find the nth digit
- hdu Problem - 1597 find the nth digit
- hdu1597 find the nth digit(规律)
- HDU 1597 find the nth digit
- MySQL常用命令
- Retrofit 2.0 + OkHttp 3.0 配置
- 第一章 引言
- 图片选择器
- 发送微信模板消息
- find the nth digit
- CleanMyMac 3偏好设置
- 我的 Android 开发实战经验总结
- 【BZOJ1064】[Noi2008]假面舞会【DFS】【分类讨论】
- android右滑返回上一个界面
- Onclick 防止多次点击造成不必要的麻烦
- ETL系列:一种遍历各个package包中过程的代码的方法
- js中 replace(/\//g, '') 什么作用.
- EventBus3.0学习小结