Advertisement
yaffar

Untitled

Jan 7th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.81 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.     int j;
  136.     for (int i = 1; i <= nTown; i++)
  137.     {
  138.         alwaysFrozen = true;
  139.         j = 1;
  140.         /*for (int j = 1; j <= nDay; j++)
  141.             if (Temps[i][j] >= 0)
  142.                 alwaysFrozen = false;*/
  143.         while (j <= nDay && alwaysFrozen == true)
  144.         {
  145.             if (Temps[i][j] >= 0)
  146.                 alwaysFrozen = false;
  147.             j++;
  148.         }
  149.         if (alwaysFrozen)
  150.         {
  151.             Db++;
  152.             frozenTowns[Db] = i;
  153.         }
  154.     }
  155. }
  156.  
  157. void PrintFrozenDays()
  158. {
  159.     cerr << "Mindig fagyos telepulesek szama: ";
  160.     cout << Db;
  161.     cerr << " Felsorolas:";
  162.     for (int i = 1; i <= Db; i++)
  163.         cout << " " << frozenTowns[i];
  164.     cout << endl;
  165. }
  166.  
  167. int main()
  168. {
  169.     cerr << "Programozas komplex beadando - 2019/2020 1e" << endl;
  170.     cerr << "Keszitette: Fonagy Denes (ia1i3q)" << endl;
  171.     cerr << "V0.50 29/12/2019" << endl;
  172.     cerr << "Feladat: 1. Mindig fagyos telepulesek" << endl;
  173.     cerr << endl << endl;
  174.  
  175.     GetChoice();
  176.     CountFrozenDays();
  177.     PrintFrozenDays();
  178.  
  179.     return 0;
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement