Untitled
raw download clone
TEXT
views 17
,
size 1244 b
/* strstr example */
#include <stdio.h>
#include <string.h>
#define MOD 1000000007

char str[1000005]={},temp[1000005]={};

int main ()
{
    int times;
    int steps;
    long long int choose;
    long long int total_len,right,temp_sum;
    long long int str_len;
    
    scanf("%d",&times);
    while(times--){
        scanf("%d",&steps);
        scanf("%s",str);
        total_len = strlen(str);
        
        for(int i=0;i<steps;i++){
            choose = str[i] - '0';
            right = total_len-i-1;
            //str_len = strlen(str);
            temp_sum=((right%MOD)*(choose-1))%MOD;
            total_len=(total_len+temp_sum)%MOD;
            
            if(total_len<0) total_len+=MOD;
            
            for(int t=0;t<right;t++){
                temp[t] = str[t+i+1];
            }
            temp[right] = '\0';

            for(int j=0;j<choose-1;j++){
                strncat(str,temp,right);
            }
//            for(int i=0;i<strlen(str);i++){
//                printf("%d",str[i]-'0');
//            }
//            printf("\n\n");
        }
//        long long int final = strlen(str)%(1000000000+7);
        printf("%lld\n",total_len);
        
    }
}
close fullscreen
Login or Register to edit or fork this paste. It's free.