Advertisement
MeehoweCK

Untitled

May 5th, 2021
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. struct Wymiary
  8. {
  9.     int x;
  10.     int y;
  11. };
  12.  
  13. struct Miasto
  14. {
  15.     string kod_kraju;
  16.     string nazwa_miasta;
  17.     Wymiary wymiary[70];
  18. };
  19.  
  20. struct Kraj
  21. {
  22.     string kod_kraju;
  23.     short liczba_powtorzen;
  24. };
  25.  
  26. void dodaj_miasto(vector<Kraj>& kraje, string kod)
  27. {
  28.     short n = kraje.size();
  29.     for(short i = 0; i < n; ++i)
  30.         if(kraje[i].kod_kraju == kod)
  31.         {
  32.             kraje[i].liczba_powtorzen++;
  33.             return;
  34.         }
  35.     Kraj nowy;
  36.     nowy.kod_kraju = kod;
  37.     nowy.liczba_powtorzen = 1;
  38.  
  39.     kraje.push_back(nowy);      // dodanie elementu na koniec wektora
  40. }
  41.  
  42. void wypisz_wektor(vector<Kraj> wektor)
  43. {
  44.     short n = wektor.size();
  45.     for(short i = 0; i < n; ++i)
  46.         cout << wektor[i].kod_kraju << '\t' << wektor[i].liczba_powtorzen << endl;
  47. }
  48.  
  49. int main()
  50. {
  51.     ifstream plik_wejscie;
  52.     Miasto miasta[50];
  53.     vector<Kraj> kraje;
  54.  
  55.     plik_wejscie.open("galerie.txt");
  56.     for(short i = 0; i < 50; ++i)
  57.     {
  58.         plik_wejscie >> miasta[i].kod_kraju >> miasta[i].nazwa_miasta;
  59.         dodaj_miasto(kraje, miasta[i].kod_kraju);
  60.         for(short j = 0; j < 70; ++j)
  61.             plik_wejscie >> miasta[i].wymiary[j].x >> miasta[i].wymiary[j].y;
  62.     }
  63.     plik_wejscie.close();
  64.  
  65.     wypisz_wektor(kraje);
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement