Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int d, i, k, j, m, h, ***M, *win, winner_count, *floors, **rooms;
- ifstream fin;
- string s;
- int main() {
- cout << "* Select the method for filling the array." << endl << "1. From file" << endl << "2. Keyboard input"
- << endl;
- cin >> s;
- switch (s[0]) {
- case '1':
- cout << "(!) The first number in the file is the number of dormitories. " << endl
- << "The next numbers are the numbers of floors in each Dorm." << endl
- << "The following numbers are the numbers of rooms on each floor." << endl
- << "The following input parameters must be filled in in turn: Dorm => number of floors => number of rooms."
- << endl << "* Enter the file name" << endl;
- cin >> s;
- fin.open(s);
- fin >> i;
- M = new int **[i];
- floors = new int[i];
- win = new int[i];
- rooms = new int*[i];
- for (m = 0; m < i; m++) {
- cout << "Enter the number of floors in the dormitory number " << m + 1 << "." << endl;
- fin >> j;
- win[m] = 0;
- floors[m] = j;
- rooms[m] = new int[j];
- M[m] = new int *[j];
- for (h = 0; h < j; h++) {
- cout << "Enter the number of rooms on the " << h + 1 << " floor in the dormitory number " << m + 1 << "."
- << endl;
- fin >> k;
- rooms[m][h] = k;
- M[m][h] = new int[k];
- }
- }
- cout << "* Enter the contents of the array separated by a space." << endl;
- for (m = 0; m < i; m++)
- for (h = 0; h < floors[m]; h++)
- for (d = 0; d < rooms[m][h]; d++) {
- fin >> M[m][h][d];
- win[m] += M[m][h][d];
- }
- fin.close();
- break;
- case '2':
- cout << "Enter the number of dormitories." << endl;
- cin >> i;
- M = new int **[i];
- floors = new int[i];
- win = new int[i];
- rooms = new int*[i];
- for (m = 0; m < i; m++) {
- cout << "Enter the number of floors in the dormitory number " << m + 1 << "." << endl;
- cin >> j;
- win[m] = 0;
- floors[m] = j;
- rooms[m] = new int[j];
- M[m] = new int *[j];
- for (h = 0; h < j; h++) {
- cout << "Enter the number of rooms on the " << h + 1 << " floor in the dormitory number " << m + 1 << "."
- << endl;
- cin >> k;
- rooms[m][h] = k;
- M[m][h] = new int[k];
- }
- }
- cout << "* Enter the contents of the array separated by a space." << endl;
- for (m = 0; m < i; m++)
- for (h = 0; h < floors[m]; h++)
- for (d = 0; d < rooms[m][h]; d++) {
- cin >> M[m][h][d];
- win[m] += M[m][h][d];
- }
- break;
- }
- winner_count = 0;
- d = 0;
- for (m = 0; m < i; m++)
- if (win[m] > winner_count) {
- winner_count = win[m];
- d = m;
- }
- cout << "Most of the residents in the dormitory number " << d + 1 << " in which currently houses " << winner_count << " students.";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement