Untitled
raw download clone
C
views 26
,
size 2157 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>
#define ll long long int
#define final 1000000007
//x=5 a[]=231
int main(void){

    int t, x;
    int ans;
    int a[1000];
    scanf("%d", &t);

    for(int i = 1; i <= t; i++){

        scanf("%d", &x);
        gets(a);

        for(int j = 0; j < x; j++){
            ans = a[i]*strlen(a)-1 + i
        }
    }

    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.