Advertisement
BrightOS

ДМД. Номер 5

Jul 8th, 2020
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int d, i, k, j, m, h, ***M, *win, winner_count, *floors, **rooms;
  7. ifstream fin;
  8. string s;
  9.  
  10. int main() {
  11.     cout << "* Select the method for filling the array." << endl << "1. From file" << endl << "2. Keyboard input"
  12.          << endl;
  13.  
  14.     cin >> s;
  15.  
  16.     switch (s[0]) {
  17.         case '1':
  18.             cout << "(!) The first number in the file is the number of dormitories. " << endl
  19.                  << "The next numbers are the numbers of floors in each Dorm." << endl
  20.                  << "The following numbers are the numbers of rooms on each floor." << endl
  21.                  << "The following input parameters must be filled in in turn: Dorm => number of floors => number of rooms."
  22.                  << endl << "* Enter the file name" << endl;
  23.             cin >> s;
  24.             fin.open(s);
  25.             fin >> i;
  26.             M = new int **[i];
  27.             floors = new int[i];
  28.             win = new int[i];
  29.             rooms = new int*[i];
  30.             for (m = 0; m < i; m++) {
  31.                 cout << "Enter the number of floors in the dormitory number " << m + 1 << "." << endl;
  32.                 fin >> j;
  33.                 win[m] = 0;
  34.                 floors[m] = j;
  35.                 rooms[m] = new int[j];
  36.                 M[m] = new int *[j];
  37.                 for (h = 0; h < j; h++) {
  38.                     cout << "Enter the number of rooms on the " << h + 1 << " floor in the dormitory number " << m + 1 << "."
  39.                          << endl;
  40.                     fin >> k;
  41.                     rooms[m][h] = k;
  42.                     M[m][h] = new int[k];
  43.                 }
  44.             }
  45.             cout << "* Enter the contents of the array separated by a space." << endl;
  46.             for (m = 0; m < i; m++)
  47.                 for (h = 0; h < floors[m]; h++)
  48.                     for (d = 0; d < rooms[m][h]; d++) {
  49.                         fin >> M[m][h][d];
  50.                         win[m] += M[m][h][d];
  51.                     }
  52.             fin.close();
  53.             break;
  54.         case '2':
  55.             cout << "Enter the number of dormitories." << endl;
  56.             cin >> i;
  57.             M = new int **[i];
  58.             floors = new int[i];
  59.             win = new int[i];
  60.             rooms = new int*[i];
  61.             for (m = 0; m < i; m++) {
  62.                 cout << "Enter the number of floors in the dormitory number " << m + 1 << "." << endl;
  63.                 cin >> j;
  64.                 win[m] = 0;
  65.                 floors[m] = j;
  66.                 rooms[m] = new int[j];
  67.                 M[m] = new int *[j];
  68.                 for (h = 0; h < j; h++) {
  69.                     cout << "Enter the number of rooms on the " << h + 1 << " floor in the dormitory number " << m + 1 << "."
  70.                          << endl;
  71.                     cin >> k;
  72.                     rooms[m][h] = k;
  73.                     M[m][h] = new int[k];
  74.                 }
  75.             }
  76.             cout << "* Enter the contents of the array separated by a space." << endl;
  77.             for (m = 0; m < i; m++)
  78.                 for (h = 0; h < floors[m]; h++)
  79.                     for (d = 0; d < rooms[m][h]; d++) {
  80.                         cin >> M[m][h][d];
  81.                         win[m] += M[m][h][d];
  82.                     }
  83.             break;
  84.     }
  85.  
  86.     winner_count = 0;
  87.     d = 0;
  88.     for (m = 0; m < i; m++)
  89.         if (win[m] > winner_count) {
  90.             winner_count = win[m];
  91.             d = m;
  92.         }
  93.  
  94.     cout << "Most of the residents in the dormitory number " << d + 1 << " in which currently houses " << winner_count << " students.";
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement