Esempio n. 1
0
/*
處理密碼一,將文章中的連續數字取出並反轉,之後再將數字相加取<10000的四位數當密碼
首先需要先將文章拆解成個別單字,再將個別單字判斷是否為連續數字,
為連續數字的話再進行反轉,反轉後再相加,相加後再取四位數
*/
int p1(char s[]){
    char *test=strtok(s," ");
    int num=0;

    while(test!=NULL){

        if(is_continue_number(test)==1){
                str_inverse(test);
                num+=atoi(test);
              //  printf("%d,%d\n",num,atoi(test));
        }

        //printf("%s\n",test);




        test=strtok(NULL," ");
    }


    return num%10000;







}
Esempio n. 2
0
int main()
{
    // Optimal fold
    const char* sequence = "CGCAGGGAUACCCGCGCC";
    char* structure;
    float mfe, gfe;
    structure = seq_fold(sequence, &mfe);
    printf("%s %s %f\n", sequence, structure, mfe);
    free(structure);

    // Ensemble fold
    structure = seq_pf_fold(sequence, &gfe);
    printf("%s %s %f\n", sequence, structure, gfe);
    free(structure);

    printf("\n");

    // Find suboptimal structures
    SOLUTION* sol = seq_subopt(sequence, 4.0);
    for(SOLUTION* s = sol; s->structure != NULL; s++)
    {
        printf("%s %s %f\n", sequence, s->structure, s->energy);
        free(s->structure);
    }
    free(sol);

    printf("\n");

    // Evaluate fe of a structure (given a sequence)...
    printf("%f\n", get_T());
    const char* test_str = "(((.((.....)))))..";
    printf("%s %s %f\n", sequence, test_str, seq_eval(sequence, test_str));
    // ... and how it changes with temperature
    set_T(15.0);
    printf("%f\n", get_T());
    printf("%s %s %f\n", sequence, test_str, seq_eval(sequence, test_str));
    set_T(37.0);

    printf("\n");

    // Take a not so different sequence with a different optimal structure
    const char* seed_seq = "AAUAGGGAUACCCGCGCC";
    structure = seq_fold(seed_seq, &mfe);
    printf("%s %s %f\n", seed_seq, structure, mfe);

    // See that is not even stable on the test fold
    printf("%s %s %f\n", seed_seq, test_str, seq_eval(seed_seq, test_str));

    // Mutate it until you get the test fold...
    char* seq = malloc(strlen(seed_seq) + 1);
    strcpy(seq, seed_seq);
    float dist = str_inverse(seq, test_str, 12345, 0);
    // ... and confirm it's its ground state
    structure = seq_fold(seq, &mfe);
    printf("%s %s %f\n", seq, structure, mfe);

    free(seq);
}