Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct adatok
- {
- int dist;
- int price;
- };
- //1. feladat
- int furthest(int N, adatok adat[])
- {
- int max = 0;
- for (int i = 0; i < N; i++)
- {
- if (max < adat[i].dist)
- {
- max = adat[i].dist;
- }
- }
- return max;
- }
- int search(int N, adatok adat[])
- {
- int max = furthest(N, adat);
- int i = 0;
- while(adat[i].dist != max)
- {
- i++;
- }
- return i+1; //A megodásban 0.tól kell indexelni !!!
- }
- //2. feladat
- int mostExpensivePrice(int N, adatok adat[])
- {
- int value = 0;
- for (int i = 0; i < N; i++)
- {
- if (value < adat[i].price && 1000 > adat[i].dist)
- {
- value = adat[i].price;
- }
- }
- if (value == 0)
- {
- value = -1;
- }
- return value;
- }
- //3.feladat
- bool isOnly(int N, int x, adatok adat[]) //egyedül van??
- {
- bool exist = true;
- int h = 0;
- for (int i = 0; i < N; i++)
- {
- if (adat[i].price == adat[x].price && i !=x)
- {
- h++;
- }
- }
- if (h > 0)
- {
- exist = false;
- }
- return exist;
- }
- int obvDist(int N, adatok adat[]) //egyértelmű távolság
- {
- int ones = 0;
- for (int i = 0; i < N; i++)
- {
- bool x = isOnly (N, i, adat);
- if (x)
- {
- ones++;
- }
- }
- return ones;
- }
- //4.feladat
- int pricePerKm(int N, int x, adatok adat[])
- {
- int priceKm = adat[x].price / adat[x].dist;
- return priceKm;
- }
- int moreThanHundred(int N, adatok adat[])
- {
- int amo = 0;
- for (int i = 0; i < N; i++)
- {
- if(pricePerKm (N, i, adat) > 100)
- {
- amo++;
- }
- }
- return amo;
- }
- void expensive(int N, adatok adat[])
- {
- int amo = moreThanHundred (N, adat);
- cerr << "Negyedik: darab+sorszam, ha tobb mint 100 ft: ";
- cout << amo;
- for (int i = 0; i < N; i++)
- {
- if(pricePerKm (N, i, adat) > 100)
- {
- cerr << " ";
- cout << i+1;
- }
- }
- }
- int main ()
- {
- //DIST PRICE
- int N;
- cin >> N;
- adatok adat[N];
- for (int i = 0; i < N; i++)
- {
- cin >> adat[i].dist >> adat[i].price;
- }
- int elso = search (N, adat);
- int masodik = mostExpensivePrice (N, adat);
- int harmadik = obvDist (N, adat);
- cerr << "Elso: legtavolabbi varos sorszama: " ;cout << elso << "\n";
- cerr << "Masodik: 1000 kilometernel kozelebbi varosok kozul a legdragabb ar: " ;cout << masodik << "\n";
- cerr << "Harmadik: egyertelmu varos tavolsagok szama: " ;cout << harmadik << "\n";
- expensive(N, adat);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement