Sicily/1177. Take Your Vitamins

根据题意进行统计就可以了

注意两点

1.整数不一定是以小数点结尾

2.不是只有维他命的名称才有空格

 1 #include <iostream>
 2 #include <string>
 3 #include <cstdio>
 4 using namespace std;
 5 string ans[100];
 6 int n;
 7 string tem;
 8 double change()
 9 {
10         int len=tem.size();
11         int i;
12         double k=0;
13         for(i=0;i<len&&tem[i]!='.';i++)
14         {
15                 k*=10;
16                 k+=tem[i]-'0';
17         }
18         double q=0;
19         for(int j=len-1;j>i;j--)
20         {
21                 q+=tem[j]-'0';
22                 q/=10;
23         }
24         return k+q;
25 }
26 int main()
27 {
28         n=0;
29         while(cin>>tem&&tem[0]!='-')
30         {
31                 double a=change();
32                 string un;
33                 cin>>un;
34                 cin>>tem;
35                 double b=change();
36                 getchar();
37                 char tem=getchar();
38                 string ta;
39                 while(tem!='\n')
40                 {
41                         ta+=tem;
42                         tem=getchar();
43                 }
44                 ans[n]=ta;
45                 n++;
46                 if(b!=0)
47                 {
48                         double c=a/b*100;
49                         if(c>=1)
50                         {
51                                 n--;
52                                 cout<<ans[n]<<" ";
53                                 printf("%.1lf ",a);
54                                 cout<<un;
55                                 printf(%.0lf%%\n",c);
56                                 //cout<<un<<" "<<(int)c<<"%"<<endl;
57                         }
58                 }
59         }
60         if(n!=0)
61         {
62                 cout<<"Provides no significant amount of:"<<endl;
63                 for(int i=0;i<n;i++)
64                 {
65                         cout<<ans[i];
66                         cout<<endl;
67                 }
68         }
69 }

转载于:https://www.cnblogs.com/congzc/archive/2011/07/09/2329941.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值