Facebook
From aa, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 130
  1. #include <fstream>
  2. #include <vector>
  3. #include <cmath>
  4. using namespace std;
  5. int dec_to_hex(int n) {
  6.     vector <int> reszty;
  7.     while (n > 0) {
  8.         int temp = n % 8;
  9.         reszty.push_back(temp);
  10.         n /= 8;
  11.     }
  12.     int x = 1;
  13.     int out = 0;
  14.     for (int i=reszty.size()-1; i >= 0; i--) {
  15.         out += reszty[i]*x;
  16.         x *= 10;
  17.     }
  18.     return out;
  19. }
  20. int hex_to_dec(int n) {
  21.     int out = 0;
  22.     int x = 0;
  23.     while (n > 0) {
  24.         int temp = n %10;
  25.         out += temp*pow(8, x);
  26.         x++;
  27.         n /= 10;
  28.     }
  29.     return out;
  30. }
  31. int licz_6(int n) {
  32.     int x = 0;
  33.     while (n > 0) {
  34.         if (n % 10 == 6) x++;
  35.         n /= 10;
  36.     }
  37.     return x;
  38. }
  39. int main() {
  40.     ifstream liczby1("liczby1.txt");
  41.     ifstream liczby2("liczby2.txt");
  42.     ofstream wyniki("wyniki.txt");
  43.     int hex, dec, old_dec, same = 0, hexb = 0, dec6 = 0, hex6 = 0;
  44.     int maxh = -1, minh = -1, ciag1 = -1, ciagd = 1, ciagdm = 0, ciag1m;
  45.     for (int i=0; i<1000;i++) {
  46.         liczby1 >> hex;
  47.         liczby2 >> dec;
  48.         if (hex > maxh || maxh == -1) maxh = hex;
  49.         if (hex < minh || minh == -1) minh = hex;
  50.         if (i == 0) ciag1 = dec;
  51.         else {
  52.             if (old_dec <= dec) {
  53.                 ciagd++;
  54.             } else {
  55.                 if (ciagdm < ciagd) {
  56.                     ciag1m = ciag1;
  57.                     ciagdm = ciagd;
  58.                 }
  59.                 ciag1 = dec;
  60.                 ciagd = 1;
  61.             }
  62.         }
  63.         old_dec = dec;
  64.         if (hex_to_dec(hex) == dec) same++;
  65.         else if (hex_to_dec(hex) > dec) hexb++;
  66.         dec6 += licz_6(dec);
  67.         hex6 += licz_6(dec_to_hex(dec));
  68.     }
  69.     //jezeli ciag konczy sie razem z plikiem
  70.     if (ciagdm < ciagd) {
  71.         ciag1m = ciag1;
  72.         ciagdm = ciagd;
  73.     }
  74.     wyniki << "Podpunkt 1" << endl;
  75.     wyniki << "Max: " << maxh << endl << "Min: " << minh << endl;
  76.     wyniki << "Podpunkt 2" << endl;
  77.     wyniki << "Dl ciagu: " << ciagdm << ", 1szy element: " << ciag1m << endl;
  78.     wyniki << "Podpunkt 3" << endl;
  79.     wyniki << "Takie same: " << same << ", 1 > 2: " << hexb << endl;
  80.     wyniki << "Podpunkt 4" << endl;
  81.     wyniki << "6stki w dziesietnym: " << dec6 << endl;
  82.     wyniki << "6stki w osemkowym: " << hex6 << endl;
  83. }
  84.