Advertisement
Guest User

pastaaaaaaaaaaaaaaaaaa

a guest
Nov 14th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 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.  
  35. string reszta(string a){
  36.  
  37. int z;
  38. string gotowy="";
  39.  
  40. z = maxpali(a).length();
  41.  
  42. for(int i=z; i<a.length(); i++){
  43.  
  44. gotowy=gotowy+a[i];
  45.  
  46. }
  47. return gotowy;
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55. string odwracanie(string a)
  56. {
  57. string wyraz="";
  58. int d=a.length();
  59.  
  60. for(int i=d-1;i>=0;i--)
  61. {
  62. wyraz+=a[i];
  63. }
  64. return wyraz;
  65. }
  66. ifstream odczyt("slowa.txt");
  67. ofstream zapis("hasla_a.txt");
  68. ofstream zapis2("slowa_a.txt");
  69. int main(int argc, char** argv) {
  70.  
  71. string a,slowomax,slowomin;
  72. int d,m=0,min=30;
  73. for(int i=0;i<1000;i++)
  74. {
  75. odczyt>>a;
  76. d=a.length();
  77. if(d>m)
  78. {
  79. m=d;
  80. slowomax=odwracanie(a);
  81. }
  82. if(d<min)
  83. {
  84. min=d;
  85. slowomin=odwracanie(a);
  86. }
  87. cout<<a<<endl;
  88. zapis<<odwracanie(a)<<endl;
  89.  
  90. }
  91. zapis2<<"Haslo o najmniejszej ilosci znakow to: "<<slowomin<<" o dlugosci: "<<min<<", a o najwiekszej ilosci znakow to: "<<slowomax<<" o dlugosci: "<<m<<endl;
  92.  
  93. cout<<maxpali("mama")<<endl<<reszta("mama");
  94.  
  95.  
  96.  
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement