Rezultati

Up. imeNalogaJezikRezultatČas oddaje
svetatrojica-2017 Prijateljske besede C++ 100/100OK 20. apr '17 @ 18:54

Test Točke Porabljen spomin Porabljen čas Status
#1 12/12 3,133 MiB 0,004 s OK
#2 12/12 3,129 MiB 0,004 s OK
#3 12/12 3,254 MiB 0,296 s OK
#4 12/12 3,250 MiB 0,351 s OK
#5 13/13 3,250 MiB 0,016 s OK
#6 13/13 3,250 MiB 0,223 s OK
#7 13/13 3,246 MiB 0,010 s OK
#8 13/13 3,320 MiB 0,284 s OK

Ocenjevani program (besede.cpp):
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;

bool druzabna(string a, string b) {
    int res = 0;
    for(int i=0; i<3; ++i) {
        if(a[i] == b[i]) res++;
        else break;
    }
    if(res == 3) return true;
    
    res = 0;
    int la, lb;
    la = a.size() - 1;
    lb = b.size() - 1;
    for(int i=0; i<3; ++i) {
        if(a[la - i] == b[lb - i]) res++;
        else break;
    }
    if(res == 3) return true;
    return false;
}

int main() {
    int n;
    cin >> n;cin.ignore();
    vector<string> bes;
    queue<int> q;
    vector<bool> v(n, false);
    int out = 0;
    string s;
    getline(cin, s);
    bes.push_back(s);
    q.push(0);
    //cout << s << endl;
    for(int i=1; i<n; ++i) {
        getline(cin, s);
        bes.push_back(s);
    }
    //cout << s << endl;
    int zdej;
    while(!q.empty()) {
        zdej = q.front();
        q.pop();
        if(v[zdej] == false) {
            out++;
            v[zdej] = true;
        }
        for(int i=0; i<n; ++i) {
            if(v[i] == false && druzabna(bes[zdej], bes[i])) {
                q.push(i);
                out++;
                v[i] = true;
            }
        }
    }
    
    cout << out << endl;
    return 0;
}