设为首页 收藏本站
查看: 795|回复: 0

[经验分享] ZOJ Problem Set

[复制链接]

尚未签到

发表于 2015-9-11 11:25:56 | 显示全部楼层 |阅读模式
ZOJ Problem Set - 1058
Currency ExchangeTime Limit: 2 Seconds                                    Memory Limit: 65536 KB                                        When Issac Bernand Miller takes a trip to another country, say to France, he exchanges  his US dollars for French francs. The exchange rate is a real number such that  when multiplied by the number of dollars gives the number of francs. For example, if the exchange rate for US dollars to French francs is 4.81724, then 10 dollars  is exchanged for 48.1724 francs. Of course, you can only get hundredth of a franc,  so the actual amount you get is rounded to the nearest hundredth. (We'll round  .005 up to.01.) All exchanges of money between any two countries are rounded  to the nearest hundredth.   Sometimes Issac's trips take him to many countries and he exchanges money from   one foreign country for that of another. When he finally arrives back home,   he exchanges his money back for US dollars. This has got Issac thinking about   how much if hisunspent US dollars is lost (or gained!) to these exchange rartes.   You'll compute how much money Issac ends up with if he exchanges it many times.   You'll always start with US dollars and you'll always end with US dollars.


  Input
  The first 5 lines of input will be the exchange rates between 5 countries,   numbered 1 through 5. Line i will five the exchange rate from country i to each   of the 5 countries. Thus the jth entry of line i will give the exchange rate   from the currencyof country i to the currency of country j. the exchange rate   form country i to itself will always be 1 and country 1 will be the US. Each   of the next lines will indicate a trip and be of the form
  N c1 c2 �� cn m
  Where 1 <= n <= 10 and c1, ��, cn are integers from 2 through 5 indicating   the order in which Issac visits the countries. (A value of n = 0 indicates end   of input, in which case there will be no more numbers on the line.) So, his   trip will be 1 ->c1 -> c2 -> �� -> cn -> 1. the real number m   will be the amount of US dollars at the start of the trip.


  Output
  Each trip will generate one line of output giving the amount of US dollars   upon his return home from the trip. The amount should be fiven to the nearest   cent, and should be displayed in the usual form with cents given to the right   of the decimal point,as shown in the sample output. If the amount is less than   one dollar, the output should have a zero in the dollars place.


  This problem contains multiple test cases!
  The first line of a multiple input is an integer N, then a blank line followed   by N input blocks. Each input block is in the format indicated in the problem   description. There is a blank line between input blocks.
  The output format consists of N output blocks. There is a blank line between   output blocks.
  
Sample Input
  1
  1 1.57556 1.10521 0.691426 7.25005
  0.634602 1 0.701196 0.43856 4.59847
  0.904750 1.42647 1 0.625627 6.55957
  1.44616 2.28059 1.59840 1 10.4843
  0.137931 0.217555 0.152449 0.0953772 1
  3 2 4 5 20.00
  1 3 100.00
  6 2 3 4 2 4 3 120.03
  0


  Sample Output
  19.98
  99.99
  120.01
  注意每次计算出money时都需要保留两位小数
  AC代码:
  #include<stdio.h>
#include<iostream>
#define MAX 10
using namespace std;
float rate[MAX][MAX];
void table()
{
for(int i=1;i<=5;i&#43;&#43;)
{
  for(int j=1;j<=5;j&#43;&#43;)
  {
   cin>>rate[j];
  }
}
}
float transform(float num)
{
num=(int)(num*100&#43;0.5);
num/=100;
return num;
}
int main()
{
int cas;
    cin>>cas;
while(cas--)
{
  table();
  int n;
  while(1)
  {
      cin>>n;
   if(n==0)break;
   int b[15];
   int i;
   for(i=0;i<n;i&#43;&#43;)
   {
    cin>>b;
   }
   float money;
   cin>>money;
   int from=1;
   for(i=0;i<n;i&#43;&#43;)
   {
    money=money*rate[from][b];
    from=b;
    money=transform(money);
   }
   money=money*rate[from][1];
   money=transform(money);
   printf(&quot;%.2lf\n&quot;,money);
  }
  if(cas!=0)cout<<endl;
}
}

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-112270-1-1.html 上篇帖子: UVa 10763 下篇帖子: (转载)发布App,赢iPad mini + 美金100$
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表