fork download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int parent1[2], parent2[2], offspring[2];
  8.  
  9. // Input sifat dari kedua orang tua dan keturunan
  10. for (int i = 0; i < 2; i++) {
  11. cin >> parent1[i];
  12. }
  13. for (int i = 0; i < 2; i++) {
  14. cin >> parent2[i];
  15. }
  16. for (int i = 0; i < 2; i++) {
  17. cin >> offspring[i];
  18. }
  19.  
  20. // Hitung kemungkinan fenotipe untuk tinggi dan jumlah anakan
  21. int tall_count = 0; // Tinggi
  22. int many_count = 0; // Jumlah anakan
  23.  
  24. // Menghitung rasio F1 untuk tinggi tanaman
  25. if (parent1[0] == 2 && parent2[0] == 2) tall_count = 4; // TT x TT
  26. else if (parent1[0] == 2 && parent2[0] == 1) tall_count = 3; // TT x Tt
  27. else if (parent1[0] == 2 && parent2[0] == 0) tall_count = 2; // TT x tt
  28. else if (parent1[0] == 1 && parent2[0] == 1) tall_count = 2; // Tt x Tt
  29. else if (parent1[0] == 1 && parent2[0] == 0) tall_count = 1; // Tt x tt
  30. else if (parent1[0] == 0 && parent2[0] == 0) tall_count = 0; // tt x tt
  31. else if (parent1[0] == 0 && parent2[0] == 1) tall_count = 1; // tt x Tt
  32. else if (parent1[0] == 0 && parent2[0] == 2) tall_count = 2; // tt x TT
  33.  
  34. // Menghitung rasio F1 untuk jumlah anakan
  35. if (parent1[1] == 2 && parent2[1] == 2) many_count = 4; // BB x BB
  36. else if (parent1[1] == 2 && parent2[1] == 1) many_count = 3; // BB x Bb
  37. else if (parent1[1] == 2 && parent2[1] == 0) many_count = 2; // BB x bb
  38. else if (parent1[1] == 1 && parent2[1] == 1) many_count = 2; // Bb x Bb
  39. else if (parent1[1] == 1 && parent2[1] == 0) many_count = 1; // Bb x bb
  40. else if (parent1[1] == 0 && parent2[1] == 0) many_count = 0; // bb x bb
  41. else if (parent1[1] == 0 && parent2[1] == 1) many_count = 1; // bb x Bb
  42. else if (parent1[1] == 0 && parent2[1] == 2) many_count = 2; // bb x BB
  43.  
  44. // Total kemungkinan genotipe
  45. int total_combinations = 16; // 4 (tinggi) * 4 (anakan)
  46.  
  47. // Menghitung kombinasi yang diinginkan
  48. int successful_combinations = 0;
  49. if ((offspring[0] == 0 && tall_count == 0) || (offspring[0] == 1 && tall_count > 0) || (offspring[0] == 2 && tall_count > 0)) {
  50. successful_combinations += tall_count;
  51. }
  52. if ((offspring[1] == 0 && many_count == 0) || (offspring[1] == 1 && many_count > 0) || (offspring[1] == 2 && many_count > 0)) {
  53. successful_combinations += many_count;
  54. }
  55.  
  56. // Hitung persentase
  57. double percentage = (double)successful_combinations / total_combinations * 100;
  58.  
  59. // Output persentase
  60. cout << fixed << setprecision(2) << percentage << "%" << endl;
  61.  
  62. return 0;
  63. }
  64.  
Success #stdin #stdout 0s 5288KB
stdin
22, 00, 00
stdout
0.00%