#include <iostream>
#include <string>
#include <vector>
#include <map>
 
using namespace std;
 
// Fungsi untuk menghasilkan gamet dari genotipe induk
vector<char> get_gametes(const string& genotype) {
    vector<char> gametes;
    gametes.push_back(genotype[0]);
    if (genotype[0] != genotype[1]) {
        gametes.push_back(genotype[1]);
    }
    return gametes;
}
 
int main() {
    // Input genotipe dari pengguna
    string induk1_genotipe, induk2_genotipe;
 
    cout << "--- Program Perhitungan Persentase F1 ---" << endl;
    cout << "Masukkan genotipe induk 1 (contoh: TT, Tt, tt): ";
    cin >> induk1_genotipe;
    cout << "Masukkan genotipe induk 2 (contoh: TT, Tt, tt): ";
    cin >> induk2_genotipe;
 
    // Menghasilkan gamet dari masing-masing induk
    vector<char> gamet1 = get_gametes(induk1_genotipe);
    vector<char> gamet2 = get_gametes(induk2_genotipe);
 
    // Menggunakan map untuk menghitung frekuensi genotipe F1
    map<string, int> frekuensi_genotipe;
 
    // Melakukan persilangan (tabel Punnett)
    for (char g1 : gamet1) {
        for (char g2 : gamet2) {
            string offspring_genotype;
            offspring_genotype += min(g1, g2); // Memastikan urutan alfabetis
            offspring_genotype += max(g1, g2);
            frekuensi_genotipe[offspring_genotype]++;
        }
    }
 
    // Menghitung total keturunan
    int total_keturunan = gamet1.size() * gamet2.size();
 
    cout << "\n--- Hasil Persilangan (F1) ---" << endl;
 
    // Menampilkan persentase genotipe dan fenotipe
    for (auto const& [genotipe, frekuensi] : frekuensi_genotipe) {
        double persentase = (static_cast<double>(frekuensi) / total_keturunan) * 100.0;
 
        // Menentukan fenotipe berdasarkan genotipe (asumsi dominasi penuh)
        string fenotipe;
        if (genotipe.find('T') != string::npos || genotipe.find('H') != string::npos) {
            fenotipe = "Dominan"; // Contoh: Tinggi, Merah, dll.
        } else {
            fenotipe = "Resesif"; // Contoh: Pendek, Putih, dll.
        }
 
        cout << "Genotipe: " << genotipe << " (" << fenotipe << ")" << endl;
        cout << "Persentase: " << persentase << "%" << endl << endl;
    }
 
    return 0;
}