Thursday, August 11, 2016
UVa 12195 Jingle Composing
UVa 12195 Jingle Composing
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#define ERROR 1e-11
using namespace std;
char input[1000000];
int main()
{
int counter, i;
double sum;
char *p;
while (gets(input))
{
if (!strcmp(input,"*")) break;
counter=0;
p = strtok(input,"/");
while (p!=NULL)
{
for (i=0, sum=0 ; p[i]>=A&&p[i]<=Z ; i++)
{
if (p[i]==W) sum += 1.0;
else if (p[i]==H) sum += 1.0/2.0;
else if (p[i]==Q) sum += 1.0/4.0;
else if (p[i]==E) sum += 1.0/8.0;
else if (p[i]==S) sum += 1.0/16.0;
else if (p[i]==T) sum += 1.0/32.0;
else if (p[i]==X) sum += 1.0/64.0;
}
if (fabs(sum-1)<ERROR) counter++;
p = strtok(NULL,"/");
}
printf("%d ",counter);
}
return 0;
}
Go to link download