Skip to content

Instantly share code, notes, and snippets.

@dafr32
Created December 2, 2013 18:50
Show Gist options
  • Save dafr32/7754811 to your computer and use it in GitHub Desktop.
Save dafr32/7754811 to your computer and use it in GitHub Desktop.
Matura Podstawa 2011 Zad4 "Hasła"
#include <iostream>
#include <fstream>
using namespace std;
bool Palindrom (string slowo)
{
for(int i=0;i<slowo.length()/2;i++)
{
if(slowo[i]!=slowo[slowo.length()-1-i]) return false;
}
return true;
}
bool DwaKolejne(string slowo)
{
for(int i=0;i<slowo.length()-1;i++)
{
if(slowo[i]+slowo[i+1]==220) return true;
}
return false;
}
int main()
{
fstream plik,plikA,plikB,plikC;
string slowo;
int ileP=0,ileN=0;
plik.open("D:\\_Profile\\Darek\\Pulpit\\MaturaRozwiazania\\2011\\Podstawa\\hasla.txt",ios::in);
plikA.open("Wynik4a.txt",ios::out);
plikB.open("Wynik4b.txt",ios::out);
plikC.open("Wynik4c.txt",ios::out);
if(plik && plikA)
{
while(plik>>slowo)
{
if(slowo.length()%2==0)
ileP++;
else
ileN++;
if(Palindrom(slowo))
{
//cout<<slowo<<endl;
plikB<<slowo<<endl;
}
if(DwaKolejne(slowo))
{
//cout <<slowo<<endl;
plikC<<slowo<<endl;
}
}
plikA<<"Liczba parzystych:"<<ileP<<endl;
plikA<<"Liczba nieparzystych:"<<ileN<<endl;
plik.close();
plikA.close();
plikB.close();
plikC.close();
}
// cout<<"Liczba parzystych:"<<ileP<<endl;
// cout<<"Liczba nieparzystych:"<<ileN<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment