Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- bool palindrom(string a){
- for(int i=0,j=a.length()-1;i<j;i++,j--){
- if(a[i]!=a[j]){
- return false;
- }
- }
- return true;
- }
- string maxpali(string a){
- string nowy="";
- for(int k=0; k<a.length();k++){
- for(int i=0;i<a.length()-k;i++){
- nowy=nowy+a[i];
- }
- if(palindrom(nowy)==true){
- return nowy;}
- nowy="";
- }
- }
- string reszta(string a){
- int z;
- string gotowy="";
- z = maxpali(a).length();
- for(int i=z; i<a.length(); i++){
- gotowy=gotowy+a[i];
- }
- return gotowy;
- }
- string odwracanie(string a)
- {
- string wyraz="";
- int d=a.length();
- for(int i=d-1;i>=0;i--)
- {
- wyraz+=a[i];
- }
- return wyraz;
- }
- string szyfrowanie(string a){
- string haslo="";
- haslo=odwracanie(reszta(a))+a;
- return haslo;
- }
- int main(int argc, char** argv) {
- ifstream odczyt("slowa.txt");
- ofstream zapis("hasla_a.txt");
- ofstream zapis2("slowa_a.txt");
- ofstream zapis3("hasla_b.txt");
- ofstream zapis4("slowa_b.txt");
- string a,slowomax,slowomin,max2,min2;
- int d,m=0,min=30,mind2=59,maxd2=0;
- for(int i=0;i<1000;i++)
- {
- odczyt>>a;
- d=a.length();
- if(d>m)
- {
- m=d;
- slowomax=odwracanie(a);
- }
- if(d<min)
- {
- min=d;
- slowomin=odwracanie(a);
- }
- cout<<a<<endl;
- zapis<<odwracanie(a)<<endl;
- zapis3<<szyfrowanie(a)<<endl;
- if(szyfrowanie(a).length()==12){
- zapis4<<szyfrowanie(a)<<endl;
- }
- if(szyfrowanie(a).length()<mind2){
- min2=szyfrowanie(a);
- mind2=szyfrowanie(a).length();
- }
- if(szyfrowanie(a).length()>maxd2){
- max2=szyfrowanie(a);
- maxd2=szyfrowanie(a).length();
- }
- }
- zapis2<<"Haslo o najmniejszej ilosci znakow to: "<<slowomin<<" o dlugosci: "<<min<<", a o najwiekszej ilosci znakow to: "<<slowomax<<" o dlugosci: "<<m<<endl;
- zapis4<<"najdluzsze haslo: "<<max2<<" a najkrotsze: "<<min2;
- cout<<szyfrowanie("kaktus");
- zapis.close();
- zapis2.close();
- zapis3.close();
- zapis4.close();
- odczyt.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement