![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//**************************************
Problem: HEU 1034 Calories from Fat
Time: 0.0180 s
Memory: 588 k
Accepted Time: 2009-05-06 17:51:46
Tips:
**************************************/
#include <stdio.h>
#include <string.h>
struct stru
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
int num;
double per;
}percent[5];
int main()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
char temp[5];
int exitflag=0,i;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
double a[5]=
{0,0,0,0,0},sum;
while(1)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
scanf("%s",temp);
if(temp[0]=='-')
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(exitflag)break;
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
exitflag=1;
sum=0;
for(i=0;i<5;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
sum+=a[i];
}
printf("%.0lf%%\n",a[0]/sum*100.0);
for(i=0;i<5;i++)a[i]=0;
}
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
exitflag=0;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
int table[]=
{9,4,4,4,7},count=0;
double ptemp=0,gtemp=0;
for(i=0;i<5;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(i!=0)scanf("%s",temp);
int len=strlen(temp);
double dtemp;
switch(temp[len-1])
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
case 'g':
sscanf(temp,"%lfg",&dtemp);
a[i]+=dtemp*table[i];
gtemp+=dtemp*table[i];
break;
case 'C':
sscanf(temp,"%lfC",&dtemp);
a[i]+=dtemp;
gtemp+=dtemp;
break;
case '%':
sscanf(temp,"%lf%%",&dtemp);
ptemp+=dtemp;
percent[count].num=i;
percent[count].per=dtemp;
count++;
break;
}
}
if(count!=0)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
sum=gtemp/(100.0-ptemp)*100.0;
for(i=0;i<count;i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
a[percent[i].num]+=sum/100.0*percent[i].per;
}
}
}
}
return 0;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
posted @
2009-05-06 17:57
主函数
阅读(
212)
评论()
编辑
收藏
举报