---
# System prepended metadata

title: 美國總統大選模擬器

---

# 美國總統大選模擬器
language: cpp
made by 黃昱凱

```
輸入範例:
0 0 1 1 1 1
1 1 0 1 0 0 
第一排(1:為男性，0:為女性)
第二排(1:支持苦瓜，0:支持芋頭)
```
```cpp=
#include<bits/stdc++.h>
using namespace std;
#define N 40
int main(){
    bool state[N];
    bool choose[N];
    int k ;
    cout <<"有投票權人數k:";
    cin >> k;
    int n;
    cout <<"實際投票人n:";
    cin >> n;
    int total_choose_1 = 0;
    int total_choose_2 = 0;
    for (int i = 0;i < n;i ++){
        cin >> state[i];
    }
    for (int i = 0;i < n;i ++){
        cin >> choose[i];
        if (choose[i] == 0){
            total_choose_1 ++;
        }else{
            total_choose_2 ++;
        }
    }
    float a, b, c;
    a = (float(n)/ float(k))*100;
    b = (total_choose_1 / float(n))*100;
    c = (total_choose_2 / float(n))*100;

    int female_1 = 0;
    int male_1 = 0;
    cout << "輸入男生州人數:" <<endl;
    int man_num;
    cin >> man_num;
    cout << "輸入男生州投票人數:" <<endl;
    int man_voted;
    cin >> man_voted;
    cout << "輸入女生州人數:" <<endl;
    int woman_num;
    cin >> woman_num;
    cout << "輸入女生州投票人數:" <<endl;
    int woman_voted;
    cin >> woman_voted;


    for(int i = 0;i < n;i ++){
        if (state[i] == 0 && choose[i] == 0){
            female_1++;
        }
        if (state[i] == 1 && choose[i] == 0){
            male_1++;
        }
    }
    float female = (female_1 / float(woman_voted));
    float male = (male_1 / float(man_voted));
    //cout << "female:" << female <<  endl;
    //cout << "male:"  << male <<  endl;
    float N_female = ((woman_voted-female_1) / float(woman_voted));
    float N_male = ((man_voted-male_1) / float(man_voted));
    cout << "參議員每州人數:" <<endl;
    int zi ;
    cin >> zi;
    cout << "每?人中選出一個眾議院議員" <<endl;
    int per;
    cin >> per;
    int first = 0;
    int zero = 0;
    cout << "選舉人團總人數:"<< (k/per)+ 2 * zi <<endl;
    cout << "投票率:"<< setprecision(4)  << a <<"%"<<  endl;
    //cout << female <<endl;
    //cout << male <<endl;
    cout <<"女生州選舉人票:"<<(zi + woman_num/per)<<endl;
    cout <<"男生州選舉人票:"<<(zi + man_num/per)<<endl;
    if (female > 0.5){
        cout<< "女生州芋頭當選，得票率:" << setprecision(4)  << female*100 <<"%"<<  endl;
        zero += (zi + woman_num/per);
    }else{
        cout<<"女生州苦瓜當選，得票率:" << setprecision(4)  << N_female*100 <<"%"<<  endl;
        first += (zi + woman_num/per);
    }
    if (male > 0.5){
        cout<< "男生州芋頭當選，得票率:" << setprecision(4)  << male*100 <<"%"<<  endl;
        zero += (zi + man_num/per);
    }else{
        cout<<"男生州苦瓜當選，得票率:" << setprecision(4)  << N_male*100 <<"%"<<  endl;
        first +=(zi + man_num/per);
    }
    cout << "選擇芋頭的比例" <<setprecision(4)  << b <<"%"<<  endl;
    cout << "選擇苦瓜的比例" <<setprecision(4)  << c <<"%"<<  endl;
    cout << "芋頭得選舉人票:"<<zero<<endl;
    cout << "苦瓜得選舉人票:"<<first<<endl;
    if (zero > first){
        cout <<"芋頭勝選"<<endl;
    }else{
        cout <<"苦瓜勝選"<<endl;
    }
}

```
(看到這裡的人肯定不正常w)