Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <locale>
- using namespace std;
- int Temps[1001][1001];
- int frozenTowns[1001];
- int nTown = 0;
- int nDay = 0;
- string choice;
- int Db = 0;
- bool alwaysFrozen;
- bool OkInt(int &x, int minx, int maxx)
- {
- bool ok = true;
- cin >> x;
- if(cin.fail())
- {
- cin.clear();
- cin.ignore(256,'\n');
- cerr << "Hiba: nem megfelelo adattipus!" << endl;
- ok = false;
- }
- else if (x < minx || x > maxx)
- {
- cerr << "Hatarerteken kivul: " << minx << " - " << maxx << endl;
- ok = false;
- }
- return ok;
- }
- void GetTemps()
- {
- for (int i = 1; i <= nTown; i++)
- for (int j = 1; j <= nDay; j++)
- cin >> Temps[i][j];
- }
- void GetManualInput()
- {
- cerr << "Kerem a telepulesek szamat: ";
- while (!OkInt(nTown, 1, 1000))
- {
- cerr << "Kerem a telepulesek szamat: ";
- }
- cerr << "Kerem a napok szamat: ";
- while (!OkInt(nDay, 1, 1000))
- {
- cerr << "Kerem a napok szamat: ";
- }
- }
- void GetManualTemps()
- {
- for (int i = 1; i <= nTown; i++)
- {
- for (int j = 1; j <= nDay; j++)
- {
- cerr << "Kerem a " << i << ". telepules " << j << ". napjanak homersekletet: ";
- while (!OkInt(Temps[i][j], -50, 50))
- {
- cerr << "Kerem a " << i << ". telepules " << j << ". napjanak homersekletet: ";
- }
- }
- }
- }
- bool IsNumber(string line)
- {
- int i = 0;
- if (line[0] == '-')
- i++;
- while (isdigit(line[i]))
- i++;
- return !(i < (int)line.length());
- }
- int StringToNumber(string line)
- {
- int i = 0;
- int number = 0;
- if (line[0] == '-')
- i++;
- while (isdigit(line[i]))
- {
- number = number * 10 + line[i] - '0';
- i++;
- }
- if (line[0] == '-')
- number *= -1;
- return number;
- }
- void Separate(string line, int &a, int &b)
- {
- int i = line.find_first_of(' ');
- string left = line.substr(0, i);
- string right = line.substr(i + 1, string::npos);
- a = StringToNumber(left);
- b = StringToNumber(right);
- }
- bool IsMultiple(string line)
- {
- return (line.find(' ') != string::npos);
- }
- void GetChoice()
- {
- cerr << "Kerem illessze be a tesztadatokat, vagy az ellenorzott kezi adatbevitelhez irja be: KEZI: ";
- getline(cin, choice);
- if (choice == "KEZI" || choice == "kezi" || choice == "Kezi")
- {
- GetManualInput();
- GetManualTemps();
- }
- else if (IsMultiple(choice))
- {
- Separate(choice, nTown, nDay);
- GetTemps();
- }
- else
- {
- cerr << "Nem ertelmezheto bemenet..." << endl;
- GetChoice();
- }
- }
- void CountFrozenDays()
- {
- for (int i = 1; i <= nTown; i++)
- {
- alwaysFrozen = true;
- for (int j = 1; j <= nDay; j++)
- if (Temps[i][j] >= 0)
- alwaysFrozen = false;
- if (alwaysFrozen)
- {
- Db++;
- frozenTowns[Db] = i;
- }
- }
- }
- void PrintFrozenDays()
- {
- cerr << "Mindig fagyos telepulesek szama: ";
- cout << Db;
- cerr << "Felsorolas:";
- for (int i = 1; i <= Db; i++)
- cout << " " << frozenTowns[i];
- cout << endl;
- }
- int main()
- {
- cerr << "Programozas komplex beadando - 2019/2020 1e" << endl;
- cerr << "Keszitette: Fonagy Denes (ia1i3q)" << endl;
- cerr << "V0.50 29/12/2019" << endl;
- cerr << "Feladat: 1. Mindig fagyos telepulesek" << endl;
- cerr << endl << endl;
- GetChoice();
- CountFrozenDays();
- PrintFrozenDays();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement