Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const string holaMon = "Bon dia a tothom!";
- /*
- * Pre: cap
- * Post: v conte una permutacio aleatoria dels elements inicials.
- */
- void shuffle(vector<int>& v) {
- for(int i=0; i<v.size(); ++i)
- swap(v[rand()%v.size()], v[rand()%v.size()]);
- }
- /*
- * Pre: cap
- * Post: Retorna una cadena la qual conte "Bon dia a tothom!" amb probabilitat 1/17!.
- */
- string resultat(vector<int>& v) {
- shuffle(v);
- string ret;
- for(int i=0; i<v.size(); ++i) ret += holaMon[v[i]];
- return ret;
- }
- int main() {
- srand(time(NULL));
- vector<int> v(holaMon.size());
- for(int i=0; i<v.size(); ++i) v[i] = i;
- string resposta;
- while(resposta != holaMon)
- resposta = resultat(v);
- cout << resposta << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement