Rezultati

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

Test Točke Porabljen spomin Porabljen čas Status
#1 12/12 3,117 MiB 0,004 s OK
#2 12/12 3,199 MiB 0,004 s OK
#3 12/12 3,598 MiB 0,290 s OK
#4 12/12 3,477 MiB 0,375 s OK
#5 13/13 3,449 MiB 0,369 s OK
#6 13/13 3,383 MiB 0,369 s OK
#7 13/13 3,398 MiB 0,363 s OK
#8 13/13 3,391 MiB 0,266 s OK

Ocenjevani program (main.cpp):
#include <iostream>
#include <math.h>
#include <vector>
#include <stdio.h>
#include <string>
#include <algorithm>

using namespace std;

class beseda{
public:
    string b;
    vector<int> pov;
    bool chk;
};

beseda* ar;

bool druz(string a, string b){
    if((a[0]==b[0]&&a[1]==b[1]&&a[2]==b[2])||
        (a[a.length()-1]==b[b.length()-1]&&
        a[a.length()-2]==b[b.length()-2]&&
        a[a.length()-3]==b[b.length()-3])){
            return true;
        }
    else{
        return false;
    }
}

int check(int k){
    int a=1;
    ar[k].chk=true;
    for(int i=0;i<ar[k].pov.size();++i){
        if(!ar[ar[k].pov[i]].chk) a+=check(ar[k].pov[i]);
    }
    return a;
}

int main(){
    int n;
    string a;
    cin>>n;
    ar=new beseda[n];
    for(int i=0;i<n;++i){
        cin>>a;
        ar[i].chk=false;
        ar[i].b=a;
    }
    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j){
            if(druz(ar[i].b,ar[j].b)){
                ar[i].pov.push_back(j);
                ar[j].pov.push_back(i);
            }
        }
    }
    cout<<check(0);
    return 0;
}