Skip to content

Instantly share code, notes, and snippets.

@dafr32
Last active December 27, 2015 12:19
Show Gist options
  • Save dafr32/7325303 to your computer and use it in GitHub Desktop.
Save dafr32/7325303 to your computer and use it in GitHub Desktop.
Matura 2013 Podstawa zadanie 4
#include <iostream>
#include <fstream>
using namespace std;
bool ZeroJeden (string napis)
{
int suma0=0,suma1=0;
for(int i=0;i<napis.length();i++)
{
if (napis[i]=='0') suma0++;
if (napis[i]=='1') suma1++;
}
if(suma0==suma1)
return true;
else
return false;
}
bool TeSame(string napis,int a)
{
int suma=0
int znak;
for(int i=0;i<napis.length();i++)
{
suma+=napis[i]-48;
}
if((a==0 && suma==0) || (a==1 && suma==napis.length()))
return true;
else
return false;
}
int main()
{
fstream plik;
string haslo;
int dlugosci[17];
int dl;
int ileP=0,ileN=0,ile01=0,ile0=0,ile1=0;
for(int i=1;i<=16;i++) dlugosci[i]=0;
plik.open("o:\\MaturaRozwiazania\\2013\\podstawa\\napisy.txt",ios::in);
if(plik)
{
while(plik>>haslo)
{
if(haslo.length()%2==0) ileP++;
if(ZeroJeden(haslo)) ile01++;
if(TeSame(haslo,0)) ile0++;
if(TeSame(haslo,1)) ile1++;
dlugosci[haslo.length()]++;
}
plik.close();
}
cout <<"Ilosc hasel parzystych :"<<ileP<<endl;
cout <<"Ilosc hasel 01 :"<<ile01<<endl;
cout <<"Ilosc hasel 0 :"<<ile0<<endl;
cout <<"Ilosc hasel 1 :"<<ile1<<endl;
for(int i=1;i<=16;i++)
cout << i << " : "<< dlugosci[i]<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment