候選人投票統計

2021-06-22 12:28:13 字數 756 閱讀 6321

輸入:

輸入候選人的人數,第二行輸入候選人的名字,第三行輸入投票人的人數,第四行輸入投票。

輸出:每行輸出候選人的名字和得票數量。

樣例輸入:

4a b c d

8a b c d e f g h

樣例輸出:

a : 1

b : 1

c : 1

d : 1

invalid : 4

#include #include #include typedef struct node

node;

node *createlist()

int getlength(node *head)

return cnt;

}void insertcandidate(node *head,char *name)

node *newnode=(node*)malloc(sizeof(node));

strcpy(newnode->name,name);

newnode->votecnt=0;

p->next=newnode;

newnode->next=null;

}void addvote(node *head,char *name)

p=p->next;

}}int main()

printf("invalid:%d",vn-validcnt);

return 0;

}

候選人得票統計

題目描述 coco班級缺少乙個生活委員,班主任組織了一次班委補選,有5個候選人參加 分別是chen,li,qian,wang,zhang 參加投票的同學有10人,每張選票上只能寫乙個人的名字。請設計程式統計每一位候選人的得票結果。輸入要求 輸入10張選票上的姓名,每張選票上只有乙個名字。輸出要求 輸...

統計候選人選票

程式設計基礎實訓指導教程 c語言 isbn 978 7 03 032846 5 p143 7.1.2 上級實訓內容 實訓內容11 統計候選人選票 分析 當前有5個候選人,每個人都包含姓名和票數資訊,建立乙個結構體陣列,存放這5個人的初始情況 假定有100人投票,通過輸入這100個人的投票資訊,在程式...

候選人得票

對候選人得票的統計程式 設有 3 個候選人,今有 10 個人參加投票,從鍵盤先後輸入這 10 個人所投的候選人的名字,要求最後輸出這 3 個候選人的得票結果。結構體與陣列 include include using namespace std struct person 宣告結構體型別person ...