伙计们,我设法完成了整个数组表的最高三位查找。我的方法正确吗?
int Man[] = { 18080,18961,18985,18761,17821,19021,18452,20000 };
int Infra[] = { 4922,4904,4993,5076,4970,4900,4718,4757 };
int Ser[] = { 13898,14424,14290,14362,12623,13139,13775,15081 };
int Trans[] = { 7382,7323,7304,7675,7147,7335,6972,7740 };
int Others[] = { 1398,1438,1414,1435,1361,1420,1450,1476 };
void main(void)
{
int first = 0;
int second = 0;
int third = 0;
int i, k ;
//Find highest
for (i = 0; i<5; i++)
{
if (Q1_2015[i] > first)
first = Q1_2015[i];
if (Q2_2015[i] > first)
first = Q2_2015[i];
if (Q3_2015[i] > first)
first = Q3_2015[i];
if (Q4_2015[i] > first)
first = Q4_2015[i];
if (Q1_2016[i] > first)
first = Q1_2016[i];
if (Q2_2016[i] > first)
first = Q2_2016[i];
if (Q3_2016[i] > first)
first = Q3_2016[i];
if (Q4_2016[i] > first)
first = Q4_2016[i];
}
//Find Second highest
for (i = 0; i<5; i++)
{
if (Q1_2015[i] < first && Q1_2015[i] > second)
second = Q1_2015[i];
if (Q2_2015[i] < first && Q2_2015[i] > second)
second = Q2_2015[i];
if (Q3_2015[i] < first && Q3_2015[i] > second)
second = Q3_2015[i];
if (Q4_2015[i] < first && Q4_2015[i] > second)
second = Q4_2015[i];
if (Q1_2016[i] < first && Q1_2016[i] > second)
second = Q1_2016[i];
if (Q2_2016[i] < first && Q2_2016[i] > second)
second = Q2_2016[i];
if (Q3_2016[i] < first && Q3_2016[i] > second)
second = Q3_2016[i];
if (Q4_2016[i] < first && Q4_2016[i] > second)
second = Q4_2016[i];
}
//Find Third highest
for (i = 0; i<5; i++)
{
if (Q1_2015[i] < first && Q1_2015[i] < second && Q1_2015[i]>third)
third = Q1_2015[i];
if (Q2_2015[i] < first && Q2_2015[i] < second && Q2_2015[i]>third)
third = Q2_2015[i];
if (Q3_2015[i] < first && Q3_2015[i] < second && Q3_2015[i]>third)
third = Q3_2015[i];
if (Q4_2015[i] < first && Q4_2015[i] < second && Q4_2015[i]>third)
third = Q4_2015[i];
if (Q1_2016[i] < first && Q1_2016[i] < second && Q1_2016[i]>third)
third = Q1_2016[i];
if (Q2_2016[i] < first && Q2_2016[i] < second && Q2_2016[i]>third)
third = Q2_2016[i];
if (Q3_2016[i] < first && Q3_2016[i] < second && Q3_2016[i]>third)
third = Q3_2016[i];
if (Q4_2016[i] < first && Q4_2016[i] < second && Q4_2016[i]>third)
third = Q4_2016[i];
}
我将数据从行更改为列,因此通过网站的方式说我需要更多的单词来编辑此帖子,这对我来说更容易执行此任务的编码,原因是我编码太多?
答案 0 :(得分:2)
所有40个中的3个最高值?
这应该不太困难
在这里要求人们做功课很不习惯,您会对此感到不满,但是如果您想尝试一下并编写您的代码,我会找您的。