Advertisement
heroys6

[softheme] [C++] Test 1

Oct 2nd, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4.  
  5. #define INP_F "INPUT.TXT"
  6. #define OTP_F "OUTPUT.TXT"
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     int num = 0, l_num = 0;
  13.  
  14.     ifstream in(INP_F, ios::in | ios::binary);
  15.     if (!in) {
  16.         cout << "Error in opening " << INP_F << "\n\n";
  17.         system("pause");
  18.         exit(1);
  19.     }
  20.  
  21.     ofstream out(OTP_F, ios::out);
  22.     if (!out) {
  23.         cout << "Error in creating " << OTP_F << "\n\n";
  24.         system("pause");
  25.         exit(1);
  26.     }
  27.  
  28.     char tmp[1];
  29.  
  30.     while (in.get(tmp[0])) {
  31.         if (atoi(tmp) == 1)
  32.             num++;
  33.         else {
  34.             if (num > l_num) l_num = num;
  35.             num = 0;
  36.         }
  37.     }
  38.  
  39.     out << "The greatest number of '1' in " << INP_F << " file: " << l_num;
  40.  
  41.     in.close();
  42.     out.close();
  43.    
  44.     system("pause");
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement