• C++ To Infinity | AtCoder


    Time LimitMemory Limit
    2000ms976MB

    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 SS is replaced with 22. Similarly, each 3 becomes 3334 becomes 44445 becomes 555556 becomes 6666667 becomes 77777778 becomes 88888888 and 9 becomes 9999999991 remains as 1.

    For example, if SS 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×10^15 days. What is the K-th character from the left in the string after  5×10^15 days?

    Input

    S
    K

    Output

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

    Sample Input #1Sample Output #1
    1214
    4
    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×10^15 days is 12222. As K=4, we should print the fourth character, 2.

    Constraints

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

    解题:

    1. #include
    2. using namespace std;
    3. long long k,cnt;
    4. string s;
    5. int main(){
    6. cin>>s>>k;
    7. for(int i=0;isize();i++) {
    8. if(s[i]!='1')break;
    9. cnt++;
    10. }
    11. if(k<=cnt)printf("1");
    12. else printf("%c",s[cnt]);
    13. return 0;
    14. }
  • 相关阅读:
    Day31、CSS
    matlab simulink仿真
    3.BeautifulSoup库
    FL Studio21.2.0官方中文版重磅发布
    计算机网络复习总结5
    JDK1.7和JDK1.8版本的新特性
    走近足球运动·与棒球相似的体育项目·第一堂棒球课
    React Native 的手势和触摸事件
    nodejs+vue+elementui英语单词学习网站python java
    ACE JET NPOI
  • 原文地址:https://blog.csdn.net/henwy/article/details/126923428