Advertisement
Guest User

qqqqqqqqqqqqqqqqqqq

a guest
Nov 14th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. bool palindrom(string a){
  6.  
  7. for(int i=0,j=a.length()-1;i<j;i++,j--){
  8.  
  9. if(a[i]!=a[j]){
  10. return false;
  11. }
  12.  
  13. }
  14. return true;
  15.  
  16. }
  17.  
  18. string maxpali(string a){
  19.  
  20. string nowy="";
  21.  
  22. for(int k=0; k<a.length();k++){
  23.  
  24. for(int i=0;i<a.length()-k;i++){
  25. nowy=nowy+a[i];
  26. }
  27. if(palindrom(nowy)==true){
  28. return nowy;}
  29. nowy="";
  30.  
  31. }
  32.  
  33. }
  34. string reszta(string a){
  35.  
  36. int z;
  37. string gotowy="";
  38.  
  39. z = maxpali(a).length();
  40.  
  41. for(int i=z; i<a.length(); i++){
  42.  
  43. gotowy=gotowy+a[i];
  44.  
  45. }
  46. return gotowy;
  47. }
  48.  
  49. string odwracanie(string a)
  50. {
  51. string wyraz="";
  52. int d=a.length();
  53.  
  54. for(int i=d-1;i>=0;i--)
  55. {
  56. wyraz+=a[i];
  57. }
  58. return wyraz;
  59. }
  60. string szyfrowanie(string a){
  61. string haslo="";
  62. haslo=odwracanie(reszta(a))+a;
  63. return haslo;
  64. }
  65.  
  66. int main(int argc, char** argv) {
  67. ifstream odczyt("slowa.txt");
  68. ofstream zapis("hasla_a.txt");
  69. ofstream zapis2("slowa_a.txt");
  70. ofstream zapis3("hasla_b.txt");
  71. ofstream zapis4("slowa_b.txt");
  72. string a,slowomax,slowomin,max2,min2;
  73. int d,m=0,min=30,mind2=59,maxd2=0;
  74. for(int i=0;i<1000;i++)
  75. {
  76. odczyt>>a;
  77. d=a.length();
  78. if(d>m)
  79. {
  80. m=d;
  81. slowomax=odwracanie(a);
  82. }
  83. if(d<min)
  84. {
  85. min=d;
  86. slowomin=odwracanie(a);
  87. }
  88. cout<<a<<endl;
  89. zapis<<odwracanie(a)<<endl;
  90. zapis3<<szyfrowanie(a)<<endl;
  91. if(szyfrowanie(a).length()==12){
  92. zapis4<<szyfrowanie(a)<<endl;
  93. }
  94. if(szyfrowanie(a).length()<mind2){
  95. min2=szyfrowanie(a);
  96. mind2=szyfrowanie(a).length();
  97. }
  98. if(szyfrowanie(a).length()>maxd2){
  99. max2=szyfrowanie(a);
  100. maxd2=szyfrowanie(a).length();
  101. }
  102.  
  103. }
  104. zapis2<<"Haslo o najmniejszej ilosci znakow to: "<<slowomin<<" o dlugosci: "<<min<<", a o najwiekszej ilosci znakow to: "<<slowomax<<" o dlugosci: "<<m<<endl;
  105. zapis4<<"najdluzsze haslo: "<<max2<<" a najkrotsze: "<<min2;
  106. cout<<szyfrowanie("kaktus");
  107. zapis.close();
  108. zapis2.close();
  109. zapis3.close();
  110. zapis4.close();
  111. odczyt.close();
  112. return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement