Advertisement
DescendingBear

STD 1, 2, 3, 4

Jan 12th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <time.h>
  4. using namespace std;
  5.  
  6. template <typename fib>
  7. fib FibNum(int m, fib a, fib b) {
  8.     if (m==0){return a;}
  9.     if (m==1){return b;}
  10.     return FibNum(m-1, a, b) + FibNum(m-2, a, b);
  11. }
  12. int main() {
  13.      string fibby = FibNum(15,string("b"),string("a"));
  14.      std::sort(fibby.begin(), fibby.end());
  15.      cout<<fibby<<endl<<endl;
  16.  
  17.      string gibberish;
  18.      cout<<"Podaj litery: ";
  19.      cin>>gibberish;
  20.      std::sort(gibberish.begin(), gibberish.end());
  21.      cout<<gibberish<<endl<<endl;
  22.  
  23.      int counta = 0;
  24.      int countb = 0;
  25.      for (int i = 0; i < fibby.size(); i++)
  26.      {
  27.      if (fibby[i] == 'a') counta++;
  28.      if (fibby[i] == 'b') countb++;
  29.      }
  30.      cout<<"W slowie Fibonacciego, litera 'a' wystepuje "<<counta<<" razy."<<endl;
  31.      cout<<"W slowie Fibonacciego, litera 'b' wystepuje "<<countb<<" razy."<<endl<<endl;
  32.  
  33.      int counta2 = 0;
  34.      int countb2 = 0;
  35.      for (int i = 0; i < gibberish.size(); i++)
  36.      {
  37.      if (gibberish[i] == 'a') counta2++;
  38.      if (gibberish[i] == 'b') countb2++;
  39.      }
  40.      cout<<"W Twoim ciagu, litera 'a' wystepuje "<<counta2<<" razy."<<endl;
  41.      cout<<"W Twoim ciagu, litera 'b' wystepuje "<<countb2<<" razy."<<endl<<endl;
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement