题干:

Problem Statement

Mr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows:

  • Each occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 3334becomes 44445 becomes 555556 becomes 6666667 becomes 77777778 becomes 88888888 and 9 becomes 9999999991 remains as 1.

For example, if S is 1324, it becomes 1333224444 the next day, and it becomes 133333333322224444444444444444 the day after next. You are interested in what the string looks like after 5×1015 days. What is the K-th character from the left in the string after 5×1015 days?

Constraints

  • S is a string of length between 1 and 100 (inclusive).
  • K is an integer between 1 and 1018 (inclusive).
  • The length of the string after 5×1015 days is at least K.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the K-th character from the left in Mr. Infinity's string after 5×1015days.

Sample Input 1

1214
4

Sample Output 1

2

The string S changes as follows:

  • Now: 1214
  • After one day: 12214444
  • After two days: 1222214444444444444444
  • After three days: 12222222214444444444444444444444444444444444444444444444444444444444444444

The first five characters in the string after 5×1015 days is 12222. As K=4, we should print the fourth character, 2.

Sample Input 2

3
157

Sample Output 2

3

The initial string is 3. The string after 5×1015 days consists only of 3.

Sample Input 3

299792458
9460730472580800

Sample Output 3

2

解题报告:

   因为是个给定的数字啊!!5e15这个数字谁都承受不了啊!!读入的字符串的大小小于100位数。所以显然我们只需要找前缀1的个数就可以了。如果查询的k大于前缀1的个数,那么就输出1后面的第一个数就是了。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 500 + 5;
ll k,cnt;
int main()
{
	string s;
	cin>>s;
	int len = s.length();
	for(int i = 0; i<len; i++) {
		if(s[i] != '1') break;
		cnt++;
	}
	cin>>k;
	if(k <= cnt) printf("1\n");
	else printf("%c\n",s[cnt]);
	
	
	return 0 ;
 }