Advertisement
yaffar

Untitled

Jan 5th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <locale>
  4.  
  5. using namespace std;
  6.  
  7. int Temps[1001][1001];
  8. int frozenTowns[1001];
  9. int nTown = 0;
  10. int nDay = 0;
  11. string choice;
  12. int Db = 0;
  13. bool alwaysFrozen;
  14.  
  15. bool OkInt(int &x, int minx, int maxx)
  16. {
  17.     bool ok = true;
  18.     cin >> x;
  19.     if(cin.fail())
  20.     {
  21.         cin.clear();
  22.         cin.ignore(256,'\n');
  23.         cerr << "Hiba: nem megfelelo adattipus!" << endl;
  24.         ok = false;
  25.     }
  26.     else if (x < minx || x > maxx)
  27.     {
  28.         cerr << "Hatarerteken kivul: " << minx << " - " << maxx << endl;
  29.         ok = false;
  30.     }
  31.     return ok;
  32. }
  33.  
  34. void GetTemps()
  35. {
  36.     for (int i = 1; i <= nTown; i++)
  37.         for (int j = 1; j <= nDay; j++)
  38.             cin >> Temps[i][j];
  39. }
  40.  
  41. void GetManualInput()
  42. {
  43.     cerr << "Kerem a telepulesek szamat: ";
  44.     while (!OkInt(nTown, 1, 1000))
  45.     {
  46.         cerr << "Kerem a telepulesek szamat: ";
  47.     }
  48.     cerr << "Kerem a napok szamat: ";
  49.     while (!OkInt(nDay, 1, 1000))
  50.     {
  51.         cerr << "Kerem a napok szamat: ";
  52.     }
  53. }
  54.  
  55. void GetManualTemps()
  56. {
  57.     for (int i = 1; i <= nTown; i++)
  58.     {
  59.         for (int j = 1; j <= nDay; j++)
  60.         {
  61.             cerr << "Kerem a " << i << ". telepules " << j << ". napjanak homersekletet: ";
  62.             while (!OkInt(Temps[i][j], -50, 50))
  63.             {
  64.                 cerr << "Kerem a " << i << ". telepules " << j << ". napjanak homersekletet: ";
  65.             }
  66.         }
  67.     }
  68. }
  69.  
  70. bool IsNumber(string line)
  71. {
  72.     int i = 0;
  73.     if (line[0] == '-')
  74.         i++;
  75.     while (isdigit(line[i]))
  76.         i++;
  77.     return !(i < (int)line.length());
  78. }
  79.  
  80. int StringToNumber(string line)
  81. {
  82.     int i = 0;
  83.     int number = 0;
  84.     if (line[0] == '-')
  85.         i++;
  86.     while (isdigit(line[i]))
  87.     {
  88.         number = number * 10 + line[i] - '0';
  89.         i++;
  90.     }
  91.     if (line[0] == '-')
  92.         number *= -1;
  93.     return number;
  94. }
  95.  
  96. void Separate(string line, int &a, int &b)
  97. {
  98.  
  99.     int i = line.find_first_of(' ');
  100.     string left = line.substr(0, i);
  101.     string right = line.substr(i + 1, string::npos);
  102.  
  103.     a = StringToNumber(left);
  104.     b = StringToNumber(right);
  105. }
  106.  
  107. bool IsMultiple(string line)
  108. {
  109.     return (line.find(' ') != string::npos);
  110. }
  111.  
  112. void GetChoice()
  113. {
  114.     cerr << "Kerem illessze be a tesztadatokat, vagy az ellenorzott kezi adatbevitelhez irja be: KEZI: ";
  115.     getline(cin, choice);
  116.     if (choice == "KEZI" || choice == "kezi" || choice == "Kezi")
  117.     {
  118.         GetManualInput();
  119.         GetManualTemps();
  120.     }
  121.     else if (IsMultiple(choice))
  122.     {
  123.         Separate(choice, nTown, nDay);
  124.         GetTemps();
  125.     }
  126.     else
  127.     {
  128.         cerr << "Nem ertelmezheto bemenet..." << endl;
  129.         GetChoice();
  130.     }
  131. }
  132.  
  133. void CountFrozenDays()
  134. {
  135.     for (int i = 1; i <= nTown; i++)
  136.     {
  137.         alwaysFrozen = true;
  138.         for (int j = 1; j <= nDay; j++)
  139.             if (Temps[i][j] >= 0)
  140.                 alwaysFrozen = false;
  141.         if (alwaysFrozen)
  142.         {
  143.             Db++;
  144.             frozenTowns[Db] = i;
  145.         }
  146.     }
  147. }
  148.  
  149. void PrintFrozenDays()
  150. {
  151.     cerr << "Mindig fagyos telepulesek szama: ";
  152.     cout << Db;
  153.     cerr << "Felsorolas:";
  154.     for (int i = 1; i <= Db; i++)
  155.         cout << " " << frozenTowns[i];
  156.     cout << endl;
  157. }
  158.  
  159. int main()
  160. {
  161.     cerr << "Programozas komplex beadando - 2019/2020 1e" << endl;
  162.     cerr << "Keszitette: Fonagy Denes (ia1i3q)" << endl;
  163.     cerr << "V0.50 29/12/2019" << endl;
  164.     cerr << "Feladat: 1. Mindig fagyos telepulesek" << endl;
  165.     cerr << endl << endl;
  166.  
  167.     GetChoice();
  168.     CountFrozenDays();
  169.     PrintFrozenDays();
  170.  
  171.     return 0;
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement