avr39-ripe

Untitled

Mar 5th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 KB | None | 0 0
  1. //В массиве хранится информация о количестве жильцов
  2. //каждой квартиры пятиэтажного дома(4 подъезда, на
  3. //каждом этаже по 2 квартиры).
  4. //а) по выбранному номеру квартиры определить количество жильцов, а также их соседей проживающих
  5. //на одном этаже;
  6. //б) определить суммарное количество жильцов для
  7. //каждого подъезда;
  8. //в) определить номера квартир, где живут многодетные
  9. //семьи.Условно будем считать таковыми, у которых
  10. //количество членов семьи превышает пять человек.
  11.  
  12. #include "pch.h"
  13. #include <iostream>
  14. #include <time.h>
  15.  
  16. using namespace std;
  17.  
  18. int main()
  19. {
  20.     //початкові параметри
  21.     //srand(time(0)); // настройка рандомізатора
  22.     const int flats = 40; // кількість квартир = кількість елементів масива
  23.     int people[flats] = { 0 }; //масив
  24.     int currFlat = 0;
  25.     int one = 0, two = 0, three = 0, four = 0;
  26.     int multiKid[flats] = {0};
  27.  
  28.  
  29.     //заповнити масив
  30.     for (int i = 0; i < flats; i++) {
  31.         people[i] = rand() % 7;
  32.     }
  33.    
  34.     //варіант а
  35.     cout << "Enter flat number" << endl;
  36.     cin >> currFlat;
  37.  
  38.     cout << "Flat " << currFlat  << " : " << people[currFlat-1] << " peoples" << endl;
  39.     (currFlat-1) % 2 == 0 ?
  40.         (cout << "Neighbors: Flat " << currFlat+1 << " : " << people[currFlat] << " peoples" << endl) :
  41.         (cout << "Neighbors: Flat " << currFlat-1 << " : " << people[currFlat] << " peoples" << endl);
  42.     cout << endl;
  43.  
  44.     //варіант б
  45.     for (int i = 0; i < flats; i++) {
  46.         if (i >= 0 and i <= 9) {
  47.             one += people[i];
  48.         }
  49.         else if (i >= 10 and i <= 19) {
  50.             two += people[i];
  51.         }
  52.         else if (i >= 20 and i <= 29) {
  53.             three += people[i];
  54.         }
  55.         else if (i >= 30 and i <= 39) {
  56.             four += people[i];
  57.         }
  58.     }
  59.     cout << "Podyezd 1: " << one << "\nPodyezd 2: " << two << "\nPodyezd 3: " << three << "\nPodyezd 4: " << four << endl;
  60.     cout << endl;
  61.  
  62.     //варiант в
  63.     for (int i = 0, j=0; i < flats; i++) {
  64.         if (people[i] > 5) {
  65.             multiKid[j] = i+1;
  66.             j++;
  67.         }
  68.     }
  69.  
  70.     cout << "Families with multiple kids flats:";
  71.     for (int i = 0; i < flats; i++) {
  72.         if (multiKid[i] > 0)
  73.         {
  74.             cout << " " << multiKid[i] << " ";
  75.         }
  76.     }
  77.     cout << endl;
  78. }
Add Comment
Please, Sign In to add comment