Untitled
raw download clone
TEXT
views 20
,
size 1204 b
#include <stdio.h>
#include <string.h>
#define MOD 1000000007
//void sub(int f,int end);
void sub(char *d, char *a, int start, int size);
char str[2000005];
char temp[2000005];
long long int s_len,add,l;
int main()
{
    int t, x;
    scanf("%d",&t);

    for(int i=0; i<t; i++)
    {
        scanf("%d",&x);
        scanf("%s",str);
        s_len = strlen(str);
        l = strlen(str);

        for(int i=1; i<=x; i++)
        {
            int left =str[i]-'0';
            add=(((l-i-1)%MOD)*(left-1))%MOD;//新增的長度
            l = (l+add)%MOD;//總長度
            if(s_len <= x && left-1 > 0)
            {
                //sub(i,s_len-1);
                sub(temp,str,i+1,s_len-i-1);
                long long int t_len = strlen(temp);
                for(int j=0; j<left-1 && s_len <=x; j++)
                {
                    strcat(str,temp);
                    s_len += t_len;
                }
            }
        }
        if(l<0)
            l+=MOD;
        //l += x-1;
        printf("%lld\n",l);
    }

    return 0;
}

void sub(char *d, char *a, int start, int size)
{
    strncpy(d, a+start, size);
    d[size] = 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.