Untitled
raw download clone
C
views 35
,
size 1281 b
#include<stdio.h>
#include<string.h>
#define MOD 1000000007

char a[10000000]={0},temp[10000000]={0};

int main(void)
{
    int t,x;
    long long add,l;

    scanf("%d",&t);
    while(t--)
    {
        scanf("%d\n",&x);
        scanf("%s",a);
        long long lena=strlen(a);
        l=lena;

        for(int i=1; i<=x; i++)
        {
             int left=a[i-1]-'0';
            add=(((l-i)%MOD)*((left-1)%MOD))%MOD;//每次加的長度
            //if(add<0)puts("!!!!!!");

            l=(l+add)%MOD;//最後字串長
            //printf("l=%ld\n",l);

            if(lena<=x&&left>1)
            {
                /*for(int k=0; k<lena-i; k++)
                {
                    temp[k]=a[i+k];//複製貼上的那串subring
                }*/
                strncpy(temp,a+i,lena-i);
                temp[lena-i]='\0';
                long long lent=strlen(temp);


                for(int n=0; n<left-1&&lena<x; n++)
                {
                    strcat(a,temp);
                    lena+=lent;
                }
                strcpy(temp,"");//temp歸零
            }
            //printf("%s\n",a);

        }
        if(l<0)
            l+=MOD;
        printf("%lld\n",l);
    }
    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.