Wednesday, November 02, 2011

[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\n",counter);
    }
    return 0;
}

No comments:

Post a Comment

Post your comment here. If you want to say something about programming problems, scripts, software etc, please try to be as descriptive as possible.

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...