简单题,一次AC,唯一需要考虑的地方是每次乘汇率后对百分位的四舍五入,还有输入输出格式要留心
#include
<
stdio.h
>
#include < math.h >
float ex[ 6 ][ 6 ]; // 各国汇率表
int trip[ 11 ]; // 旅游路线
float start; // 起始资金
void solve( int n)
{
int i,j,k;
float re,temp,key,mid;
for (i = 0 ;i <= n;i ++ )
{
re = start * ex[trip[i]][trip[i + 1 ]];
temp = re * 100 ;
mid = floor(temp);
key = temp - mid;
if (key >= 0.500 )
{
start = (mid + 1 ) / 100 ;
}
else
{
start = mid / 100 ;
}
}
printf( " %.2f/n " ,start);
}
int main()
{
freopen( " 1058.txt " , " r " ,stdin);
int n,nn;
// n某条线路中的旅程数
// nn总输入块数
int i,j,k,l;
for (i = 1 ;i <= 5 ;i ++ )
for (j = 1 ;j <= 5 ;j ++ )
ex[i][j] = 0.0 ;
trip[ 0 ] = 1 ;
scanf( " %d " , & nn);
for (k = 1 ;k <= nn;k ++ )
{
for (i = 1 ;i <= 5 ;i ++ )
for (j = 1 ;j <= 5 ;j ++ )
scanf( " %f " , & ex[i][j]);
while (scanf( " %d " , & n) != EOF && n != 0 )
{
for (i = 1 ;i <= n;i ++ )
scanf( " %d " , & trip[i]);
trip[n + 1 ] = 1 ;
scanf( " %f " , & start);
solve(n);
}
if (k != nn) printf( "/n " );
}
fclose(stdin);
return 0 ;
}
#include < math.h >
float ex[ 6 ][ 6 ]; // 各国汇率表
int trip[ 11 ]; // 旅游路线
float start; // 起始资金
void solve( int n)
{
int i,j,k;
float re,temp,key,mid;
for (i = 0 ;i <= n;i ++ )
{
re = start * ex[trip[i]][trip[i + 1 ]];
temp = re * 100 ;
mid = floor(temp);
key = temp - mid;
if (key >= 0.500 )
{
start = (mid + 1 ) / 100 ;
}
else
{
start = mid / 100 ;
}
}
printf( " %.2f/n " ,start);
}
int main()
{
freopen( " 1058.txt " , " r " ,stdin);
int n,nn;
// n某条线路中的旅程数
// nn总输入块数
int i,j,k,l;
for (i = 1 ;i <= 5 ;i ++ )
for (j = 1 ;j <= 5 ;j ++ )
ex[i][j] = 0.0 ;
trip[ 0 ] = 1 ;
scanf( " %d " , & nn);
for (k = 1 ;k <= nn;k ++ )
{
for (i = 1 ;i <= 5 ;i ++ )
for (j = 1 ;j <= 5 ;j ++ )
scanf( " %f " , & ex[i][j]);
while (scanf( " %d " , & n) != EOF && n != 0 )
{
for (i = 1 ;i <= n;i ++ )
scanf( " %d " , & trip[i]);
trip[n + 1 ] = 1 ;
scanf( " %f " , & start);
solve(n);
}
if (k != nn) printf( "/n " );
}
fclose(stdin);
return 0 ;
}