feihung

Untitled

Mar 2nd, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6. int silnia_iter( int liczba ){
  7.     int result = 1;
  8.     if ( liczba > 0 ){
  9.         for ( int i = 2; i <= liczba; i++){
  10.             result = result * i;
  11.         }
  12.     }
  13.     return result;
  14. }
  15.  
  16. int silnia_rekur( int liczba ){
  17.     int result;
  18.     if ( liczba == 1 ){
  19.         return 1;
  20.     } else {
  21.         return(silnia_rekur(liczba - 1)*liczba);
  22.     }
  23. }
  24.  
  25. void wspak( string znaki ){
  26.     static int dlugosc = znaki.length() -1;
  27.     cout << znaki[dlugosc];
  28.     if (dlugosc > 0) {
  29.         dlugosc--;
  30.         wspak(znaki);
  31.     }
  32. }
  33.  
  34. bool palindrom( string znak ){
  35.     int dlugosc = znak.length();
  36.     int i = 0;
  37.     bool check = true;
  38.  
  39.     if ( dlugosc % 2 == 1 ){
  40.         while( i < (dlugosc-1)/2 ){
  41.             if ( znak[i] != znak[dlugosc-i-1] ){
  42.                 check = false;
  43.                 break;
  44.             }
  45.             i++;
  46.         }
  47.     } else {
  48.         while ( i < dlugosc/2 ){
  49.             if(znak[i] != znak[dlugosc-i-1]){
  50.                 check = false;
  51.                 break;
  52.             }
  53.             i++;
  54.         }
  55.     }
  56.     return check;
  57. }
  58.  
  59. void  menu(){
  60.     int wybor;
  61.     do{
  62.         cout << "1. Sprawdz palindrom." << endl;
  63.         cout << "2. Wyjscie" << endl;
  64.         cin >> wybor;
  65.         if ( wybor == 1 ){
  66.             string wyraz;
  67.             cout << "Podaj wyraz" << endl;
  68.             cin >> wyraz;
  69.             if (palindrom(wyraz)){
  70.                 cout << "To jest palindrom" << endl;
  71.             } else {
  72.                 cout << "To nie jest palindrom" << endl;
  73.             }
  74.         }
  75.     } while ( wybor == 1 );
  76. }
  77.  
  78.  
  79. int main(){
  80.     menu();
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment