主题:[讨论]求助:如何同时从小到大排列两组数据
linux下c++中
数据如下:
日期(string) 最高温(int) 最低温(int)
1/1/2007 34 23
1/2/2007 34 22
1/3/2007 40 24
.
.
.
12/30/2007 35 20
12/31/2007 28 12
希望将其排成,高温从小到大;如果高温温度一样,低温也从小到大。
如:(excel搞的)
10/30/07 64 46
04/18/07 65 33
03/12/07 65 36
11/17/07 65 42
04/16/07 65 43
10/20/07 66 34
10/29/07 66 38
10/08/07 66 39
04/04/07 66 40
05/21/07 67 37
我写的,以及数据都在附件里面,现在只能将高温小到大排列。低温怎么办?
(cpp里因为前面还有其他内容,为了方便看,我已经删除无用内容。)
题目是要求取年中,高温从小到大排列后中间的5天,并且如果高温一样,低温也必须从小到大。
The five median days were:
4/26/2009 High: 55 Low: 38
9/13/2009 High: 56 Low: 45
9/14/2009 High: 56 Low: 47
4/30/2009 High: 58 Low: 46
4/25/2009 High: 58 Low: 48
新手。希望大家指点下。先谢谢各位。
我写的在下面
ifstream dataFile ("slc_2007.txt");
int five_median_high_temps[366];
int five_median_low_temps[366];
string dates_for_median_temps[366];
// Reads in the data.
for (int i = 0; i < 365; i ++)
{
string date;
int high_temp, low_temp;
dataFile >> date;
dataFile >> high_temp;
dataFile >> low_temp;
five_median_low_temps = low_temp;
five_median_high_temps = high_temp;
dates_for_median_temps = date;
}
// Find the five 'median days' of the year.
for ( start = 0; start < end; start++ )
{
int hottestPos = start;
for (int i = start + 1; i < end; i++)
if ( five_median_high_temps > five_median_high_temps[hottestPos] )
hottestPos = i;
int temp = five_median_high_temps[hottestPos];
five_median_high_temps[hottestPos] = five_median_high_temps[start];
five_median_high_temps[start] = temp;
int temp2 = five_median_low_temps[hottestPos];
five_median_low_temps[hottestPos] = five_median_low_temps[start];
five_median_low_temps[start] = temp2;
string temp3 = dates_for_median_temps[hottestPos];
dates_for_median_temps[hottestPos] = dates_for_median_temps[start];
dates_for_median_temps[start] = temp3;
}
数据如下:
日期(string) 最高温(int) 最低温(int)
1/1/2007 34 23
1/2/2007 34 22
1/3/2007 40 24
.
.
.
12/30/2007 35 20
12/31/2007 28 12
希望将其排成,高温从小到大;如果高温温度一样,低温也从小到大。
如:(excel搞的)
10/30/07 64 46
04/18/07 65 33
03/12/07 65 36
11/17/07 65 42
04/16/07 65 43
10/20/07 66 34
10/29/07 66 38
10/08/07 66 39
04/04/07 66 40
05/21/07 67 37
我写的,以及数据都在附件里面,现在只能将高温小到大排列。低温怎么办?
(cpp里因为前面还有其他内容,为了方便看,我已经删除无用内容。)
题目是要求取年中,高温从小到大排列后中间的5天,并且如果高温一样,低温也必须从小到大。
The five median days were:
4/26/2009 High: 55 Low: 38
9/13/2009 High: 56 Low: 45
9/14/2009 High: 56 Low: 47
4/30/2009 High: 58 Low: 46
4/25/2009 High: 58 Low: 48
新手。希望大家指点下。先谢谢各位。
我写的在下面
ifstream dataFile ("slc_2007.txt");
int five_median_high_temps[366];
int five_median_low_temps[366];
string dates_for_median_temps[366];
// Reads in the data.
for (int i = 0; i < 365; i ++)
{
string date;
int high_temp, low_temp;
dataFile >> date;
dataFile >> high_temp;
dataFile >> low_temp;
five_median_low_temps = low_temp;
five_median_high_temps = high_temp;
dates_for_median_temps = date;
}
// Find the five 'median days' of the year.
for ( start = 0; start < end; start++ )
{
int hottestPos = start;
for (int i = start + 1; i < end; i++)
if ( five_median_high_temps > five_median_high_temps[hottestPos] )
hottestPos = i;
int temp = five_median_high_temps[hottestPos];
five_median_high_temps[hottestPos] = five_median_high_temps[start];
five_median_high_temps[start] = temp;
int temp2 = five_median_low_temps[hottestPos];
five_median_low_temps[hottestPos] = five_median_low_temps[start];
five_median_low_temps[start] = temp2;
string temp3 = dates_for_median_temps[hottestPos];
dates_for_median_temps[hottestPos] = dates_for_median_temps[start];
dates_for_median_temps[start] = temp3;
}