无算法,但有些麻烦
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define maxl 100
#define eps 10E-9
char st[maxl];
char unit;
double fat;
double tot;
void input()
{
int temp;
char ch;
sscanf(st, "%d%c", &temp, &ch);
bool percent;
int p = 0;
int c = 0;
if (ch == '%')
{
percent = true;
p += temp;
}
else if (ch == 'g')
{
percent = false;
c += temp * 9;
fat += temp * 9;
}
else
{
percent = false;
c += temp;
fat += temp;
}
int f[4] =
{ 4, 4, 4, 7 };
for (int i = 0; i < 4; i++)
{
int a;
scanf("%d%c", &a, &ch);
if (ch == '%')
p += a;
else if (ch == 'g')
c += a * f[i];
else
c += a;
}
tot += c / (100.0 - p) * 100;
if (percent)
fat += c / (100.0 - p) * temp;
}
int main()
{
//freopen("t.txt", "r", stdin);
while (scanf("%s", st), strcmp(st, "-"))
{
fat = 0;
tot = 0;
do
{
input();
} while (scanf("%s", st), strcmp(st, "-"));
printf("%d%%\n", (int)(fat * 100 / tot + 0.5 + eps));
}
return 0;
}