Advertisement
AdrianMadajewski

58. Systemy Liczbowe

Nov 27th, 2018
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <climits>
  4. #include <Windows.h>
  5. #include <cmath>
  6. #include <fstream>
  7.  
  8. using namespace std;
  9.  
  10. int na10(string &liczba, int podstawa)
  11. {
  12.     int len = liczba.length();
  13.     int wynik = 0;
  14.     int potega = 1;
  15.     int znak = 1;
  16.     int i = 0;
  17.  
  18.     if (liczba[0] == '-')
  19.     {
  20.         znak = -1;
  21.         i = 1;
  22.     }
  23.  
  24.     for (int j = len - 1; j >= i; j--)
  25.     {
  26.         int x = liczba[j] - '0';
  27.         wynik = wynik + (x * potega);
  28.         potega = potega * podstawa;
  29.     }
  30.     return znak * wynik;
  31. }
  32.  
  33. string naSystem(int liczba, int podstawa)
  34. {
  35.     string wynik = "";
  36.     string wzorzec = "012345678";
  37.     int znak = 1;
  38.  
  39.     if (liczba < 0)
  40.     {
  41.         znak = -1;
  42.         liczba = -liczba;
  43.     }
  44.     while (liczba > 0)
  45.     {
  46.         wynik = wzorzec[liczba % podstawa] + wynik;
  47.         liczba = liczba / podstawa;
  48.     }
  49.     if (znak == -1) wynik = '-' + wynik;
  50.     return wynik;
  51. }
  52. struct Pomiar
  53. {
  54.     string czas;
  55.     string temperatura;
  56. };
  57.  
  58. int main()
  59. {
  60.     fstream dane1;
  61.     fstream dane2;
  62.     fstream dane3;
  63.  
  64.     dane1.open("dane_systemy1.txt", ios::in);
  65.     dane2.open("dane_systemy2.txt", ios::in);
  66.     dane3.open("dane_systemy3.txt", ios::in);
  67.  
  68.     const int N = 1095;
  69.  
  70.     Pomiar *S1 = new Pomiar[N];
  71.     Pomiar *S2 = new Pomiar[N];
  72.     Pomiar *S3 = new Pomiar[N];
  73.  
  74.     for (int i = 0; i < N; i++)
  75.     {
  76.         dane1 >> S1[i].czas >> S1[i].temperatura;
  77.         dane2 >> S2[i].czas >> S2[i].temperatura;
  78.         dane3 >> S3[i].czas >> S3[i].temperatura;
  79.     }
  80.  
  81.     dane1.close();
  82.     dane2.close();
  83.     dane3.close();
  84.  
  85.     fstream wynik;
  86.     string w = "wyniki_systemy.txt";
  87.  
  88.     // WCZYTANIE - KONIEC
  89.  
  90.     // 58.1 - zmienne
  91.     int min1, min2, min3;
  92.     min1 = min2 = min3 = INT_MAX;
  93.  
  94.     // 58.2 - zmienne
  95.     int stan = 12;
  96.     int blad = 0;
  97.  
  98.     // 58.3 - zmienne
  99.     int max1, max2, max3;
  100.     int rekordow = 0;
  101.     max1 = max2 = max3 = INT_MIN;
  102.  
  103.     for (int i = 0; i < N; i++)
  104.     {
  105.         // 58.1
  106.         int t1 = na10(S1[i].temperatura, 2);
  107.         int t2 = na10(S2[i].temperatura, 4);
  108.         int t3 = na10(S3[i].temperatura, 8);
  109.  
  110.         if (t1 < min1) min1 = t1;
  111.         if (t2 < min2) min2 = t2;
  112.         if (t3 < min3) min3 = t3;
  113.  
  114.         // 58.2
  115.         int czas1 = na10(S1[i].czas, 2);
  116.         int czas2 = na10(S2[i].czas, 4);
  117.         int czas3 = na10(S3[i].czas, 8);
  118.  
  119.         if (czas1 != stan && czas2 != stan && czas3 != stan)
  120.             blad++;
  121.         stan += 24;
  122.  
  123.         // 58.3
  124.         bool rekord = false;
  125.         if (t1 > max1)
  126.         {
  127.             max1 = t1;
  128.             rekord = true;
  129.         }
  130.         if (t2 > max2)
  131.         {
  132.             max2 = t2;
  133.             rekord = true;
  134.         }
  135.         if (t3 > max3)
  136.         {
  137.             max3 = t3;
  138.             rekord = true;
  139.         }
  140.         if (rekord) rekordow++;
  141.     }
  142.  
  143.     wynik.open(w.c_str(), ios::out);
  144.  
  145.     wynik << 58.1 << endl;
  146.     wynik << "min S1: " << naSystem(min1, 2) << endl;
  147.     wynik << "min S2: " << naSystem(min2, 2) << endl;
  148.     wynik << "min S3: " << naSystem(min3, 2) << endl;
  149.  
  150.     wynik << 58.2 << endl;
  151.     wynik << "blednych dni: " << blad << endl;
  152.  
  153.     wynik << 58.3 << endl;
  154.     wynik << "dni rekordowych: " << rekordow << endl;
  155.  
  156.     // 58.4 tylko dla S1
  157.     int maxskok = INT_MIN;
  158.     for(int i = 0; i < N; i++)
  159.         for (int j = i + 1; j < N; j++)
  160.         {
  161.             double a = na10(S1[i].temperatura, 2) - na10(S1[j].temperatura, 2);;
  162.             double ry = a * a;
  163.  
  164.             // Zaokraglenie w gore
  165.             double skok = ceil(ry / abs(i - j));
  166.  
  167.             if (skok > maxskok)
  168.                 maxskok = skok;
  169.         }
  170.  
  171.     wynik << 58.4 << endl;
  172.     wynik << "rekordowy skok: " << maxskok;
  173.  
  174.     delete[] S1;
  175.     delete[] S2;
  176.     delete[] S3;
  177.  
  178.     wynik.close();
  179.  
  180.     system("pause");
  181.     return 0;
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement