Last active
March 14, 2016 14:18
-
-
Save RicardoLara/8cf1e4a751e7b31125d3 to your computer and use it in GitHub Desktop.
Programa para Crsipin...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
map<char,int> Letras; | |
map<char,int>::iterator it; | |
int fact(int n){ | |
return (n == 1 || n == 0) ? 1 : fact(n - 1) * n; | |
} | |
int denominador(char letra){ | |
int deno = 1; | |
for (it = Letras.begin(); it != Letras.end(); it++) | |
if(it->first == letra) deno *= 1; | |
else deno *= fact(it->second); | |
return deno; | |
} | |
int combina(char letra){ | |
int espacios = 0, combinaciones; | |
for (it = Letras.begin(); it != Letras.end(); it++) | |
if(it->first != letra) | |
espacios += it->second; | |
espacios++; | |
cout << "Tenemos " << espacios << " espacios" << endl; | |
cout << espacios << "C" << Letras[letra] << endl; | |
combinaciones = fact(espacios)/( fact(espacios - Letras[letra]) * fact(Letras[letra]) ); | |
return combinaciones * ( fact(espacios-1)/denominador(letra)); | |
} | |
int main(){ | |
int n_Letras = 0; | |
string palabra; | |
char letra; | |
printf("Meteme la palabra: "); cin >> palabra; | |
for(int i=0; i<palabra.length(); i++) | |
Letras[palabra[i]]++; | |
for (it = Letras.begin(); it != Letras.end(); it++){ | |
cout << it->first << " => " << it->second << endl; | |
n_Letras += it->second; | |
} | |
cout << "La palabra tiene " << n_Letras << " letras" << endl; | |
cout << "Siendo asi, podemos pedir que metas una letra: "; cin >> letra; | |
cout << "Haciendo las operaciones tendriamos -> " << combina(letra) << " como resultado" << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment