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;
- }
- ifstream odczyt("slowa.txt");
- ofstream zapis("hasla_a.txt");
- ofstream zapis2("slowa_a.txt");
- int main(int argc, char** argv) {
- string a,slowomax,slowomin;
- int d,m=0,min=30;
- 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;
- }
- zapis2<<"Haslo o najmniejszej ilosci znakow to: "<<slowomin<<" o dlugosci: "<<min<<", a o najwiekszej ilosci znakow to: "<<slowomax<<" o dlugosci: "<<m<<endl;
- cout<<maxpali("mama")<<endl<<reszta("mama");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement