Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. // PW_zadania_4.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <cmath>
  7. #include <string>
  8. using namespace std;
  9.  
  10. int _tmain(int argc, _TCHAR* argv[])
  11. {
  12. int num;
  13. do
  14. {
  15. cout << "Witamy w programie pw_zadania_4" << endl << "Podaj numer zadania a program zacznie prace " << endl << "1.Zadanie 1" << endl << "2.Zadanie 2" << endl << "3.Zadanie 3" << endl << "0.Koniec" << endl;
  16. cin >> num;
  17. cin.ignore();
  18. switch (num)
  19. {
  20. case 1:
  21. {
  22. char tab [30];
  23. cout << "Wpisz dowolny wyraz (max 30znakow), a program sprawdzi czy jest on palindromem" << endl;
  24. cin >> tab;
  25. cout << tab << endl;
  26. int n = strlen(tab);
  27.  
  28. for(int a = n-1; a>0; a--) cout << tab[a] << endl;
  29.  
  30. bool nie_jest_palindromem, wyraz_nieparzysty;
  31. nie_jest_palindromem = false;
  32. wyraz_nieparzysty = false;
  33.  
  34. int i, L2;
  35. for(i=0; i < n; i++)
  36. {
  37. if(tab[i]==tab[n-1-i])cout << "";
  38.  
  39. else nie_jest_palindromem = true;
  40.  
  41.  
  42. L2=n % 2 == 0 ? 1 : 0;
  43. if(L2==1)cout << "";
  44.  
  45. else wyraz_nieparzysty = true;
  46. }
  47. if (nie_jest_palindromem == true) cout << "wyraz nie jest palindromem" << endl;
  48. else cout << "wyraz jest palindromem" << endl;
  49.  
  50. if (wyraz_nieparzysty == true) cout << "wyraz nieparzysty" << endl << endl;
  51. else cout << "wyraz parzysty" << endl << endl;
  52. cin.get();
  53. break;
  54. }
  55. case 0:
  56. return 0;
  57. default:
  58. cout<<"Nieprawidlowa cyfra, wybierz cyfre z menu odpowiadajaca ktoremus z dzialan" << endl;
  59. }
  60. }while(num!=0);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement