Zadanie 58.2 ze zbioru CKE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <bitset>

#define ROZMIAR 3
//3 pliki danych

using namespace std;


int bledne_pomiary()
{
        ifstream file[ROZMIAR]; //3 pliki
        string nazwy[ROZMIAR] = {"dane_systemy1.txt", "dane_systemy2.txt", "dane_systemy3.txt"};
         
        for(int i=0;i<ROZMIAR;i++) {
                file[i].open(nazwy[i].c_str());
        }
       
        string liczba1, liczba2;
        long zegar[ROZMIAR]; //przeliczone na system 10 stany zegara (indeks tablicy = nr pliku 0,1,2)
        char* endptr;//błąd konwersji z systemu na dziesiętny
       
        int b = 0;//ilosc bledow
       
        int poprawny = 12;
        if(file[0].good() && file[1].good() && file[2].good() ) {
          while(!file[0].eof())
          {
              int system = 1;
               
              for(int i=0;i<ROZMIAR;i++) {
                file[i]>>liczba1 >> liczba2;
                zegar[i] =  strtol(liczba1.c_str(), &endptr, system*= 2); //mnoży system razy dwa, na początku 1 => 2, 2=>4, 4=>8
                }
       
       
//       cout<<zegar[0]<<" "<<zegar[1]<<" "<<zegar[2]<< " = "<<poprawny;
   
       if(zegar[0] != poprawny && zegar[1] != poprawny && zegar[2] != poprawny)
       {
                b++;//błędy ++
//            cout<<" Error";
       }
       
//       cout<<endl;
     
       poprawny += 24; //dodaj 24h - do następnej doby przechodzimy
     }
  }
 
  return b;
}


int main(int argc, char** argv)
{
 ofstream fileOut;
 fileOut.open("wyjscie 58-2.txt");

 int bledy = bledne_pomiary();

 cout<< bledy;
 fileOut<< "58.2: " << bledy <<endl;

 fileOut.close();
 return 0;
}