1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #include <stdio.h> #include <stdlib.h> #include <string.h> struct vote { int id; char name[10]; int number; }vote_people[4] ={ {1, "李明",0 },{2, "刘亮", 0 },{3, "王鱼", 0 },{4, "艾日", 0 } };
int main() { for (int i = 1; i <= 10; i++) { int id; printf("请输入投票编号:"); scanf("%d", &id); for (int j = 0; j < 4; j++) { if (id == vote_people[j].id) { vote_people[j].number++; break; } } printf("\n"); } int arr[4] = {0,1,2,3}; for (int i = 0; i < 4; i++) { for (int j = i + 1; vote_people[i].number < vote_people[j].number; j++) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } for (int i = 0; i < 4; i++) { printf("编号:%d 姓名:%s 得票数:%d\n", vote_people[arr[i]].id, vote_people[arr[i]].name, vote_people[arr[i]].number); } return 0; }
|