ZOJ1058: Currency Exchange

os posted @ 2013年9月09日 13:34 in ACM , 783 阅读

acm 题目List

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1058

 

#include <stdio.h>
int main ()
{
	double a[6][6];
	int b[13];
	int n;
	int flag = 0;
	int cases;
	scanf("%d", &cases);

	while(cases--)
	{
		int i,j;
		if (flag) printf("\n");
		flag = 1;

		for (i = 1; i <= 5; i++)
			for (j = 1; j <=5; j++)
				scanf("%lf", &a[i][j]);

		while(scanf("%d", &n) && n)
		{
			b[1] = 1;
			for (i = 2; i <= n+1; i++)
				scanf("%d", &b[i]);
			b[i] = 1;

			double m = 0;
			scanf("%lf", &m);

			for (i = 2; i <= n+2; i++)
			{
				m = m*a[b[i-1]][b[i]];
				m = (int)(m*100+0.5);
				m /= 100;
			}
			printf("%.2lf\n", m);
		}
	}

	return 0;
}

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter