Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. ifstream plik("liczby.txt");
  10. int max = 0,counterDlugosci = 0,counterLiczby = 0,couterJedynek = 0,maxJedynek = 0,counterParzystych = 0;
  11. string x,naj;
  12.  
  13. if (plik.good())
  14. {
  15. while (!plik.eof())
  16. {
  17. couterJedynek = 0;
  18. plik >> x;
  19. if (x[x.length()-1] == '0')
  20. {
  21. counterParzystych++;
  22. }
  23. if (x.length() > max)
  24. {
  25. max = x.length();
  26. naj = x;
  27.  
  28. }
  29. if (x.length() == 8 || x.length() == 9)
  30. {
  31. counterDlugosci++;
  32. }
  33. if (x == "10100011")
  34. {
  35. counterLiczby++;
  36. }
  37. for (int i = 0; i < x.length(); i++)
  38. {
  39. if (x[i] == '1')
  40. {
  41. couterJedynek++;
  42. }
  43. }
  44. if (couterJedynek > maxJedynek)
  45. {
  46. maxJedynek = couterJedynek;
  47. }
  48. }
  49. cout << "Ilosc liczb parzystych: " << counterParzystych << endl;
  50. cout << "Najdluzsza liczba to: " << naj << " ma: " << max << " znakow." << endl;
  51. cout << "Najwieksza liczba jedynek w liczbie: " << maxJedynek << endl;
  52. cout << "Ilosc liczb o dlugosci 8 lub 9: " << counterDlugosci << endl;
  53. cout << "Liczba 10100011 wystepuje " << counterLiczby << " razy" << endl;
  54. }
  55.  
  56.  
  57.  
  58. system("pause");
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement