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

char tempstr[1000005] = {0};
char str[1000005] = {0};

void substr(char *dest, char *a, int start, int size){
    strncpy(dest, a+start, size);
    dest[size] = 0;
}

int main(){
    int t, x;
    scanf("%d", &t);
    for(int l=0; l<t; l++){
        scanf("%d", &x);

        scanf("%s", str);
        long long int s_len, len;
        len = s_len = strlen(str);

        for(int i=0; i<x; i++){
            if( (s_len <= x) && (str[i]-'0') && s_len-i-1>=0 ){

                substr(tempstr, str, i+1, s_len-i-1); // 擷取右半部字串
                for(int j=0; (j < str[i]-'0') && s_len<=x  ; j++){
                    strcat(str,tempstr); // 貼上
                    s_len += (len-i-1); // 計算當前字串長度
                }
            }
            len += ( ((len - i - 1) % MOD ) *  (str[i]-'0'-1) ) % MOD;
            //if( len < 0 ) system("pause");
        }
        printf("%lld\n", len%MOD);
    }
}
close fullscreen
Login or Register to edit or fork this paste. It's free.