Rezultati

Up. imeNalogaJezikRezultatČas oddaje
PIN Prijateljske besede C++ 100/100OK 20. apr '17 @ 18:16

Test Točke Porabljen spomin Porabljen čas Status
#1 12/12 3,195 MiB 0,004 s OK
#2 12/12 3,188 MiB 0,004 s OK
#3 12/12 3,324 MiB 0,120 s OK
#4 12/12 3,313 MiB 0,120 s OK
#5 13/13 3,250 MiB 0,010 s OK
#6 13/13 3,250 MiB 0,053 s OK
#7 13/13 3,246 MiB 0,016 s OK
#8 13/13 3,254 MiB 0,071 s OK

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

using namespace std;

bool isCompanion(string &w1, string &w2)
{
  //  cout << w1 << " " << w2 << endl;
    int l1 = w1.size();
    int l2 = w2.size();

    /*cout << w1[l1 - 3] << w1[l1 - 2] << w1[l1 - 1] << endl;
    cout << w2[l2 - 3] << w2[l2 - 2] << w2[l2 - 1] << endl;
*/
    return (w1[0] == w2[0] && w1[1] == w2[1] && w1[2] == w2[2]) || 
           (w1[l1 - 3] == w2[l2 - 3] && w1[l1 - 2] == w2[l2 - 2] && w1[l1 - 1] == w2[l2 - 1]);
}

int main()
{    
    int n;
    cin >> n;
    n -= 1;

    string word;
    vector<string> words;
    vector<bool> isWordValid; 
    vector<int> nextCompanions;
    vector<string> companions;

    string companion;
    cin >> companion;
    companions.push_back(companion);

    int friends = 1;
    for(int i = 0; i < n; i++)
    {
        cin >> word;
        words.push_back(word);
        isWordValid.push_back(true);
    }
     
    bool change = true;
    int iter = 0;
    while(change)
    {
        change = false;
        int companionsNr = companions.size();

        nextCompanions.resize(0);
        for(int j = 0; j < companionsNr; j++)
        {
            for(int i = 0; i < n; i++)
            {
                if(isWordValid[i] && isCompanion(companions[j], words[i]))
                {
                    isWordValid[i] = false;
                    nextCompanions.push_back(i);
                    friends++;
                    change = true;
                   // cout << iter << ": " << companions[j] << " - " << words[i] << endl;
                }
                //cout << words[i] << " - " << isCompanion(words[0], words[i]) << endl;
            }
        }
        companions.resize(0);
        int l = nextCompanions.size();
        for(int j = 0; j < l; j++)
        {
            companions.push_back(words[nextCompanions[j]]);
        }
        iter++;
    }
    
    cout << friends << endl;

    return 0;
}