标签:i++ content struct include desc end strong top color
题目描述:
按要求,给国家进行排名。
4 4 4 8 1 6 6 2 4 8 2 2 12 4 0 1 2 3 4 2 8 10 1 8 11 2 8 12 3 8 13 4 0 3
1:3 1:1 2:1 1:2
#include<iostream> using namespace std; struct paixu{ int i; int j; }paixu[5]; struct guojia{ int gold; int medal; int people; double goldper; double medalper; }guo[1000]; int paixu1(int x,int n){ int num=1; for(int i=0;i<n;i++){ if(guo[i].gold>guo[x].gold) num++; } return num; } int paixu2(int x,int n){ int num=1; for(int i=0;i<n;i++){ if(guo[i].medal>guo[x].medal) num++; } return num; } int paixu3(int x,int n){ int num=1; for(int i=0;i<n;i++){ if(guo[i].goldper>guo[x].goldper) num++; } return num; } int paixu4(int x,int n){ int num=1; for(int i=0;i<n;i++){ if(guo[i].medalper>guo[x].medalper) num++; } return num; } void mim(){ if(paixu[1].j<=paixu[2].j) { if(paixu[1].j<=paixu[3].j){ if(paixu[1].j<=paixu[4].j){ paixu[0]=paixu[1]; return; } else { paixu[0]=paixu[4]; return; } } else if(paixu[3].j<=paixu[4].j){ paixu[0]=paixu[3]; return; } else { paixu[0]=paixu[4]; return; } } else if(paixu[2].j<=paixu[3].j){ if(paixu[2].j<=paixu[4].j){ paixu[0]=paixu[2]; return; } else { paixu[0]=paixu[4]; return; } } else if(paixu[3].j<=paixu[4].j){ paixu[0]=paixu[3]; return; } else { paixu[0]=paixu[4]; return; } } int main(){ int n,m,i,a; while(cin>>n>>m){ for(i=0;i<n;i++){ cin>>guo[i].gold>>guo[i].medal>>guo[i].people; guo[i].goldper=guo[i].gold/guo[i].people; guo[i].medalper=guo[i].medal/guo[i].people; } for(i=0;i<m;i++){ cin>>a; paixu[1].i=1; paixu[1].j=paixu1(a,n); paixu[2].i=2; paixu[2].j=paixu2(a,n); paixu[3].i=3; paixu[3].j=paixu3(a,n); paixu[4].i=4; paixu[4].j=paixu4(a,n); mim(); cout<<paixu[0].j<<":"<<paixu[0].i<<endl; } cout<<endl; } return 0; }
标签:i++ content struct include desc end strong top color
原文地址:https://www.cnblogs.com/bernieloveslife/p/9736615.html