10

 avatar
gorazd
c_cpp
a month ago
1.6 kB
2
Indexable
1kolok_OOP
#include <iostream>
#include <cstring>
#include  <iomanip>
using namespace std;

struct Igrac {
    char username[15];
    int level;
    int points;
};
struct KompjuterskaIgra {
    char name[20];
    Igrac players[30];
    int numberOfPlayers;
};

void najdobarIgrac(KompjuterskaIgra *lista, int n) {
    KompjuterskaIgra popularna = lista[0];
    int max = lista[0].numberOfPlayers;
    for (int i = 1; i<n; i++) {
        if (lista[i].numberOfPlayers>max) {
            max = lista[i].numberOfPlayers;
            popularna = lista[i];
        }
    }
    int maxPoints = popularna.players[0].points;
    Igrac best = popularna.players[0];
        for (int j = 0; j<popularna.numberOfPlayers; j++) {
            if (popularna.players[j].points > max) {
                max = popularna.players[j].points;
                best = popularna.players[j];
            }
            else if (popularna.players[j].points == max and popularna.players[j].level>best.level) {
                best = popularna.players[j];
            }
        }

    cout<<"Najdobar igrac e igracot so korisnicko ime "<<best.username<<" koj ja igra igrata "<<popularna.name<<endl;
}

int main() {
    int n;
    cin>>n; //number of it stores;
    KompjuterskaIgra igri[n];
    for (int i = 0; i < n; i++) {
        cin>>igri[i].name;
        cin>>igri[i].numberOfPlayers;
        for (int j = 0; j<igri[i].numberOfPlayers; j++) {
            cin>>igri[i].players[j].username>>igri[i].players[j].level>>igri[i].players[j].points;
        }
    }
    najdobarIgrac(igri, n);

}
Editor is loading...
Leave a Comment