Untitled
raw download clone
TEXT
views 64
,
size 1026 b
#include<stdio.h>
#include<string.h>
#define MOD 1000000007
int main()
{
    int x,i,l,left,j,L,k;
    int m,z;
    int t;
    int add;
    int tlen;
    char    s[100000];
    char subs[100000];
    char temp[100000];
    scanf("%d",&t);
    for(k=1;k<=t;k++){
    scanf("%d",&x);
    scanf("%s",&s);
    strncpy(subs,&s[0],strlen(s));
    l=strlen(subs);
    L=strlen(subs);
    for(i=1; i<=x; i++)
    {   left=s[i-1]-'0';
        add=(l-i)%MOD*(left-1)%MOD;
        l=(l+add)%MOD;     //計算長度
        if(l<=x&&left>1)
        {
        memset(temp, '\0', strlen(temp));
       for (z=i,m=0;z<L; z++, m++){
                    temp[m] = s[z];  
                }
                             //貼s到temp
      tlen=strlen(temp);
         for(j=1;j<=left-1&&L<=x;j++){
        strcat(s,temp);
        L=L+tlen;
                            //貼temp到s 做Left-1次

         }


        }



    }
    if(l<0)l=l+MOD;

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