Untitled
raw download clone
C
views 21
,
size 3055 b
#include<stdio.h>
#include<string.h>
#define N 150000

char a[N], b[N];

int f(int al, int ar, int bl, int br){//0頭, len-1尾, 0, len-1,是用來提出陣列中的字元

    int length, i, j;
    int amid, bmid;//中間切一半用的

    for(i = al; i <= ar; i++){//第一個字元到最後一個字元

        for(j = bl; j <= br; j++){//第一個字元到最後一個字元

            if(a[i] != b[j]) break;//break到第19行的if述句
            else if(i == ar) return 1;//
        }
        if(a[i] != b[j]) break;//再一次跳出for迴圈,到第21行
    }
    length = ar - al + 1;

    if(length % 2 == 1) return 0;
    else{
        amid = (al + ar + 1)/2;
        bmid = (bl + br + 1)/2;

        if( f(al, amid-1, bl, bmid-1) && f(amid, ar, bmid, br)) return 1;
        else if( f(al, amid-1, bmid, br) && f(amid, ar, bl, bmid-1)) return 1;
        else return 0;
    }
}

int main(void){

    int len;
    scanf("%s%s", a, b);
    len = strlen(a);

    if(f(0, len-1, 0, len-1)) printf("YES\n");//傳進兩字串的左右極限字元
    else printf("NO\n");

    return 0;
}
//整個程式會有三種情況。一 我進行第一次比




#include<stdio.h>

int n,a[50],ans=0;
int k;

int f(int num,int sum) //num=a陣列編號 sum=目前加總總合
{
        if(sum==k)
        {
            ans++;
            return ans;
            //printf("%d %d ",sum,a[num]);
        }
        if(sum>k||num>n) return 0;
        else
        {
            f(num+1,sum+a[num]);
            f(num+1,sum);
        }
    return 0;
}

int main()
{
    int i;
    scanf("%d%d",&n,&k);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    f(1,0);
    printf("%d\n",ans);
    return 0;
}





#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 10000001
#define MOD 1000000007
#define ll long long int

char str[N];
char temp[N];

void substr(ll st, ll en)
{
    ll count = 0;
    for(ll i=st; i<en;i++){
        temp[count++] = str[i];
    }
}

int main(){
    ll t, x, s_len;
    ll l = 0;

    scanf("%lld", &t);
    while(t--){
        scanf("%lld", &x);
        scanf("%s", str);

        s_len = l = strlen(str);

        for(ll i=1; i<=x; i++){
            ll paste = (str[i-1]-'0');
            ll add = (((paste-1)%MOD)*((l-i)%MOD))%MOD;
            l = (l%MOD + add%MOD)% MOD;
            //printf("paste = %lld , l = %3lld , add = %3lld\n", paste, l, add);

            if(s_len <= x && paste > 1){
                // substr(i, s_len);
                // substr Àò¨ú str(i~end)ªº¤l¦r¦ê
                strncpy(temp, str+i, s_len-i+1);

                ll t_len = strlen(temp);
                for(ll j=0; j<(paste-1) && s_len <= x; j++){
                    strcat(str, temp);
                    s_len += t_len;
                }
                //printf("%s: %s\n", temp, str);
            }

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

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