Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int main()
- {
- ifstream plik("liczby.txt");
- int max = 0,counterDlugosci = 0,counterLiczby = 0,couterJedynek = 0,maxJedynek = 0,counterParzystych = 0;
- string x,naj;
- if (plik.good())
- {
- while (!plik.eof())
- {
- couterJedynek = 0;
- plik >> x;
- if (x[x.length()-1] == '0')
- {
- counterParzystych++;
- }
- if (x.length() > max)
- {
- max = x.length();
- naj = x;
- }
- if (x.length() == 8 || x.length() == 9)
- {
- counterDlugosci++;
- }
- if (x == "10100011")
- {
- counterLiczby++;
- }
- for (int i = 0; i < x.length(); i++)
- {
- if (x[i] == '1')
- {
- couterJedynek++;
- }
- }
- if (couterJedynek > maxJedynek)
- {
- maxJedynek = couterJedynek;
- }
- }
- cout << "Ilosc liczb parzystych: " << counterParzystych << endl;
- cout << "Najdluzsza liczba to: " << naj << " ma: " << max << " znakow." << endl;
- cout << "Najwieksza liczba jedynek w liczbie: " << maxJedynek << endl;
- cout << "Ilosc liczb o dlugosci 8 lub 9: " << counterDlugosci << endl;
- cout << "Liczba 10100011 wystepuje " << counterLiczby << " razy" << endl;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement