There are all kinds of people in this world. It happens that we have become friends. This is not fate. It is just that we should be friends.

——Green Book



When I first met a problem which name is Find the Nth Character in nowcoder,I find this problem is interesting for mind.After solving this,I find a similar problem like this in HDU which name is find the Nth digit.
Link:
Find the Nth Character in nowcoder
find the Nth digit in HDU

Find the Nth Character

Description:
Mr Cheng今天在给HLJU的同学们上程序算法课的时候出了一道找规律的题目,题目表述如下
假设:

现在要求上课的同学们把所有的串依次连接起来,于是得到:
S=aababcabcdabcde...
那么你能告诉Mr Cheng在S串中的第N个字母是多少吗?

输入描述:
输入首先是一个数字K,代表有K次询问(1<=K<=1000)

接下来的K行每行有一个整数N(1<=N<=10000)

输出描述:
对于每次询问,输出串中第个位置对应的字母。

示例1
输入
6
1
2
3
4
5
10
输出
a
a
b
a
b
d

Code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    int n;
    cin>>t;
    while (t--)
    {
          cin>>n;
          int a = 1;
          char ans='a';
          while ( n > a )
          {
                n -= a;  
                a++;
          }
          n%=26;
          if(n==0) n=26;
          ans+=n-1;
         cout<<ans<<endl;
    }
    return 0;
}

find the nth digit

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

Code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    int n;
    cin>>t;
    while (t--)
    {
          cin>>n;
          int a = 1;
          char ans='1';
          while ( n > a )
          {
                n -= a;  
                a++;
          }
          n%=9;
          if(n==0) n=9;
          ans+=n-1;
         cout<<ans<<endl;
    }
    return 0;
}

Intentional analysis:
We can easily find there is a few different between these two codes above.In fact,to solve this problem,the main thinking is find the Nth in the correct position.And the regular is

1 2 3 4 5 6 7 8 9 10...
1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567891...

Through this,you may understand this more.
I know that what I said is not so clearly,so just think through these codes if you can't understand enough.