B - A Very Long String
Time limit : 2sec / Stack limit : 256MB / Memory limit : 256MB
Problem
The string S is exactly the same as the string A repeated 10100 times.
Output the B-th letter of the string S.
Input
Input will be given in the following format from the Standard Input.
A B
- On the first line, you will be given a string A(1≦|A|≦50). Each character in the string A will be a lowercase English alphabet letter.
- On the second line, you will be given a integer B(1≦B≦1,000,000,000).
Achievements and Points
- When you pass every test case where 1≦B≦100,000 , you will be awarded 20 points.
- In addition, if you pass all the rest test cases you will be awarded 80 more points.
Output
Output the B-th letter of the string S in one line. Make sure to insert a line break at the end of the output.
Input Example 1
- abc
- 7
Output Example 1
- a
The beggining of string S is abcabcabcabc
...
Therefore, the 7th letter is a
.
Input Example 2
- bbb
- 9
Output Example 2
- b
Each letter in the string S is b
, so the 9th letter is also b
.
Input Example 3
- kljhasdfkjahfadfakhsdfaklh
- 1000000000
OutPut Example 3
- h
Note that a large number could be in the input.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(){
char A[100] = { 0 };
gets(A);
int B;
scanf("%d", &B);
int num = strlen(A);
int remader = B%num;
if (remader != 0){
cout << remader << endl;
cout << A[remader - 1] << endl;
}
else {
cout << remader << endl;
cout << A[num - 1] << endl;
}
//puts(A);
system("pause");
return 0;
}