#include <cstdio> #include <map> using namespace std; inline int digit(int n) { int d = 0; while (n) { n /= 10; d++; } return d; } inline int digitOf(int n, int pos) { char s[99]; sprintf(s, "%d", n); return s[pos - 1] - '0'; } int main() { long long sum[40000], len[40000]; for (long long i = 1, j = 0; j < 2147483647; i++) { len[i] = digit(i); sum[i] = sum[i - 1] + len[i]; j += sum[i]; } int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); for (int i = 0; n > sum[i]; n -= sum[i++]); int num; for (num = 1; n > len[num]; n -= len[num++]); printf("%d\n", digitOf(num, n)); } return 0; }
Hello, I am a CS student from Taiwan.
I am learing English and Programming.
I'll save source code of some problems or small programs without comments in this blog.
I would recommend you not to read solution from others before you solved the problem.
(這邊專門存放沒有任何註解的小程式/OJ題目程式碼)
2013年8月24日
UVa 10706 - Number Sequence
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言