Rezultati

Up. imeNalogaJezikRezultatČas oddaje
programatorji-2017 Prijateljske besede C++ 100/100OK 20. apr '17 @ 16:56

Test Točke Porabljen spomin Porabljen čas Status
#1 12/12 3,156 MiB 0,004 s OK
#2 12/12 3,215 MiB 0,004 s OK
#3 12/12 3,223 MiB 0,162 s OK
#4 12/12 3,219 MiB 0,120 s OK
#5 13/13 3,148 MiB 0,010 s OK
#6 13/13 3,219 MiB 0,053 s OK
#7 13/13 3,211 MiB 0,010 s OK
#8 13/13 3,223 MiB 0,071 s OK

Ocenjevani program (besede.cpp):
#include <iostream>
#include <string>
#include <deque>
using namespace std;

const int N = 3001;
string beseda[N];

bool staPri(string& a, string& b){
    bool flag = true;
    for(int i = 0;i < 3;i++)
        if(a[i] != b[i])
            flag = false;
    if(flag) return true;
    flag = true;
    for(int i = 1;i < 4;i++)
        if(a[a.length() - i] != b[b.length() - i])
            flag = false;
    return flag;
}

deque<int> dq;
bool vis[N];
int main(){
    int n, ans = 0;
    cin>>n;
    for(int i = 0;i < n;i++){
        cin>>beseda[i];
    }
    dq.push_back(0);
    
    while(!dq.empty()){
        int top = dq.front();
        dq.pop_front();
        
        if(vis[top]) continue;
        vis[top] = true;
        ans++;
        
        for(int i = 0;i < n;i++){
            if(staPri(beseda[i], beseda[top]) && !vis[i])
                dq.push_back(i);
        }
    }
    cout<<ans<<"\n";
    return 0;
}