Rezultati

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

Test Točke Porabljen spomin Porabljen čas Status
#1 12/12 3,145 MiB 0,004 s OK
#2 12/12 3,406 MiB 0,010 s OK
#3 12/12 11,840 MiB 0,138 s OK
#4 12/12 11,750 MiB 0,114 s OK
#5 13/13 11,793 MiB 0,047 s OK
#6 13/13 11,793 MiB 0,077 s OK
#7 13/13 11,734 MiB 0,047 s OK
#8 13/13 11,797 MiB 0,089 s OK

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

using namespace std;
bool adj[3000][3000],checked[3000];
int a;

int check(int c){
    if (checked[c]) return 0;
    checked[c] = true;
    int ret = 1;
    for (int i=0;i<a;i++){
        if (adj[i][c]){
            ret += check(i);
        }
    }
    return ret;
}

int main()
{
    int b,c,d,e,f;
    cin >> a;
    string s[a];
    for (int i=0;i<a;i++) {cin >> s[i]; adj[i][i] =false; checked[i] = false;}
    for (int i=0;i<a;i++) for (int j=i+1;j<a;j++) {
        b = s[i].length();
        c = s[j].length();
        if (s[i][0] == s[j][0] && s[i][1] == s[j][1] && s[i][2] == s[j][2]){
            adj[i][j] = true;
            adj[j][i] = true;
        }
        if (s[i][b-1] == s[j][c-1] && s[i][b-2] == s[j][c-2] && s[i][b-3] == s[j][c-3]){
            adj[i][j] = true;
            adj[j][i] = true;
        }
    }
    cout << check(0);
    return 0;
}