Advertisement
Guest User

Untitled

a guest
Feb 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int lado[] = {1, 2, 3, 4, 5, 6};
  4. const int MAX = 100;
  5. int pos[MAX];
  6. int dados;
  7. map<int, int>contagem;
  8. void run(int dado){
  9.     if(dado == dados) {
  10.         int soma = 0;
  11.         for(int i = 0; i < dados; ++i){
  12.             soma += lado[pos[i]];
  13.         }
  14.         contagem[soma]++;
  15.     }else {
  16.         for(int i = 0; i < 6; ++i){
  17.             pos[dado] = i;
  18.             run(dado+1);
  19.         }
  20.     }
  21. }
  22. int main() {
  23.  
  24.     vector<int> temp;
  25.     for(int i = 1; i <= 6; ++i)temp.push_back(i);
  26.     printf("Indique a quantidade de dados:\n");
  27.     scanf("%d", &dados);
  28.     run(0);
  29.     for(map<int,int>::iterator pair = contagem.begin(); pair != contagem.end(); ++pair) {
  30.         printf("%d -> %lf\n", pair->first, 100.0 * pair->second / (6 * dados));
  31.     }
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement