Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. #pragma hdrstop
  2. #pragma argsused
  3.  
  4. #ifdef _WIN32
  5. #include <tchar.h>
  6. #else
  7.   typedef char _TCHAR;
  8.   #define _tmain main
  9. #endif
  10.  
  11. #include <stdio.h>
  12. #include <iostream>
  13. #include <windows.h>
  14. #include <conio.h>
  15. using namespace std;
  16.  
  17.  
  18. double fact (int n)
  19. {
  20.     if (n<=1) return 1.0;
  21.     else return fact(n-1)*n;
  22. }
  23.  
  24.  
  25. int _tmain(int argc, _TCHAR* argv[])
  26. {   int s=0;
  27.     bool flag=1;
  28.     int kol=0;
  29.     int g=0;
  30.     SetConsoleCP(1251);
  31.     SetConsoleOutputCP(1251);
  32.     char str[15];
  33.     char b[15];
  34.     int c[15];
  35.     cout << " Введите строку : ";
  36.     gets(str);
  37.     int count=0;  //кол-во уникальных букв
  38.     int t=1;
  39.     double rez;
  40.     int pr=1;
  41.  
  42.  
  43.     b[0]=str[0];
  44.  
  45.     for (int i=0; str[i]; i++)  // считаем кол-во символов
  46.     {
  47.     s++;
  48.     }
  49.  
  50.   /*    for (int i=0; str[i]; i++)
  51.     {
  52.     b[i]=str[i];
  53.     }
  54.  
  55.     for (int i = 0; str[i]; i++)
  56.     {
  57.     cout << b[i];
  58.     }    */
  59.  
  60.  
  61.  
  62.     b[0]=str[0];
  63.     for (int i = 1; str[i]; i++)
  64.     {
  65.         //содержится ли такая буква уже в b
  66.         for (int j=0; j<i; j++)
  67.         {
  68.             if (str[i] == b[j])
  69.             {
  70.                 flag = 0;
  71.                 break;
  72.             }
  73.         }
  74.         //если такой буквы еще нет, заносим
  75.         if (flag)
  76.         {
  77.             b[t] = str[i];
  78.             count++;
  79.             t++;
  80.         }
  81.         flag = 1;
  82.     }
  83.  
  84.  
  85.     for (int t=0; t < count + 1; t++)
  86.     {
  87.         cout << b[t] << " " ;
  88.     }
  89.  
  90.     for (int t=0; b[t]; t++)
  91.     {
  92.         for ( int i = 0; str[i]; i++)
  93.         {
  94.             if (b[t]==str[i])
  95.             {
  96.              kol++;
  97.             }
  98.  
  99.         }
  100.      c[g]=kol;
  101.      g++;
  102.      kol=0;
  103.  
  104.     }
  105.  
  106.  
  107.    /*   for (int g=0; g < count + 1; g++)
  108.     {
  109.         cout << c[g] << " ";
  110.     } */
  111.  
  112.  
  113.     for (g = 0; g < count + 1; g++)
  114.     {
  115.      pr=pr*fact(c[g]);
  116.     }
  117.  
  118.  
  119.      rez = fact(s) / pr;
  120.      cout << " Количество различных анаграмм" << " " << rez;
  121.  
  122.  
  123.     getch();
  124.     return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement