Rezultati

Up. imeNalogaJezikRezultatČas oddaje
borjenas-2019 Biodiverziteta C++ 100/100OK 09. maj '19 @ 19:13

Test Točke Porabljen spomin Porabljen čas Status
#1 [več] 20/20 4,750 MiB 0,000 s OK
#2 [več] 20/20 6,145 MiB 0,000 s OK
#3 [več] 20/20 6,141 MiB 0,000 s OK
#4 [več] 20/20 6,145 MiB 0,000 s OK
#5 [več] 20/20 6,145 MiB 0,000 s OK

Ocenjevani program (biodiverziteta.cpp):
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int myabs(int a) {
    if (a < 0) {
        return -a;
    }
    return a;
}

struct DNK {
    int num_A;
    int num_C;
    int num_T;
    int num_G;

    DNK() {
        num_A = 0;
        num_C = 0;
        num_T = 0;
        num_G = 0;
    }

    DNK(const DNK& a) {
        num_A = a.num_A;
        num_C = a.num_C;
        num_T = a.num_T;
        num_G = a.num_G;
    }

    DNK(const DNK& a, const DNK& b) {
        num_A = myabs(a.num_A - b.num_A);
        num_C = myabs(a.num_C - b.num_C);
        num_T = myabs(a.num_T - b.num_T);
        num_G = myabs(a.num_G - b.num_G);
    }

};

void PrintDNK (const DNK& a) {
    cout << "DNK: " << a.num_A << " " << a.num_C << " "  << a.num_T << " " << a.num_G << " " << endl;
}

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    string s1;
    cin >> s1;
    
    vector<DNK> dnk_s_1 = vector<DNK>(n + 1);
    dnk_s_1[0] = DNK();
    for (int i = 1; i < n + 1; ++i) {
        DNK d = DNK(dnk_s_1[i - 1]);

        //cout << "i: " << i;
        //PrintDNK(d);
        //cout << "s: " << s1[i] << endl;

        switch (s1[i - 1])
        {
            case 'A':
                d.num_A++;
                break;

            case 'T':
                d.num_T++;
                break;

            case 'C':
                d.num_C++;
                break;

            case 'G':
                d.num_G++;
                break;
        
            default:
                break;
        }

        dnk_s_1[i] = d;

    }


    string s2;
    cin >> s2;
    
    vector<DNK> dnk_s_2 = vector<DNK>(m + 1);

    for (int i = 1; i < m + 1; ++i) {
        DNK d = DNK(dnk_s_2[i - 1]);
        //cout << "i: " << i;
        //PrintDNK(d);
        //cout << "s: " << s2[i] << endl;

        switch (s2[i - 1])
        {
            case 'A':
                d.num_A++;
                break;

            case 'T':
                d.num_T++;
                break;

            case 'C':
                d.num_C++;
                break;

            case 'G':
                d.num_G++;
                break;
        
            default:
                break;
        }

        dnk_s_2[i] = d;

    }


    for (int i = 0; i < q; ++i) {
        int si, ti, ui, vi;
        cin >> si >> ti >> ui >> vi;
        si--;ti;ui--;vi;
        DNK a_1 = dnk_s_1[si];
        //PrintDNK(a_1);
        DNK a_2 = dnk_s_1[ti];
        //cout <<"ti:" << ti << n << endl;
        //PrintDNK(a_2);
        DNK a = DNK(a_1, a_2);
        //PrintDNK(a);

        DNK b_1 = dnk_s_2[ui];
        ////PrintDNK(b_1);
        DNK b_2 = dnk_s_2[vi];
        ////PrintDNK(b_2);
        DNK b = DNK(b_1, b_2);
        //PrintDNK(b);
        

        DNK r = DNK(a, b);
        //PrintDNK(r);
        cout << r.num_A + r.num_C + r.num_G + r.num_T << endl;
    }
}