Bullshit Bingo

Time Limit: 1000MS

 

Memory Limit: 65536K

Total Submissions: 1815

 

Accepted: 630

Description

Bullshit Bingo is a game to make lectures, seminars or meetings less boring. Every player has a card with 5 rows and 5 columns. Each of the 25 cells contains a word (the cell in the middle has always the word "BINGO" written in it). Whenever a player hears a word which is written on his card, he can mark it. The cell in the middle is already marked when the game starts. If a player has marked all the words in a row, a column or a diagonal, he stands up and shouts "BULLSHIT". After this, the game starts over again. 

Sitting in a lecture, you observe that some students in the audience are playing Bullshit Bingo. You wonder what the average number of different words is until "BULLSHIT" is exclaimed. For the purpose of this problem, a word consists of letters of the English alphabet ('a' to 'z' or 'A' to 'Z'). Words are separated by characters other than letters (for example spaces, digits or punctuation). Do the comparison of words case-insensitively, i.e., "Bingo" is the same word as "bingo". When counting the number of different words, ignore the word BULLSHIT (indicating the end of the game), and consider only the words of the current game, i.e., if a word has already occurred in a previous game, you may still count it in the current game. If the last game is unfinished, ignore the words of that game.

Input

The input consists of the text of the lecture, with "BULLSHIT" occurring occasionally. The first game starts with the first word in the input. Each occurrence of "BULLSHIT" indicates the end of one game. 
You may assume, that 

  • the word "BULLSHIT" occurs only in uppercase letters 
  • every word has at most 25 characters, and each line has at most 100 characters 
  • there are at most 500 different words before a game ends 
  • the players follow the rules, so there is no need to check if a game is valid or not

Output

The output consists of one number: the average number of different words needed to win a game. Write the number as a reduced fraction in the format shown below. Reduced fraction means that there should be no integer greater than 1 which divides both the numerator and denominator. For example if there were 10 games, and the number of different words in each game summed up to 55, print "11 / 2".

Sample Input

Programming languages can be classified BULLSHIT into following types:
- imperative and BULLSHIT procedural languages
- functional languages
- logical BULLSHIT programming languages
- object-oriented BULLSHIT languages

Sample Output

9 / 2

Hint

In the sample input, there are 4 completed games. The number of different words is 5, 5, 4 and 4, respectively.

Source

Ulm Local 2005

 解题报告:题意就是以BULLSHIT为一组的结束标志,来统计一下一组中不同单词的个数,再求出每组不同单词个数的和处理总的组数即可,但是还得化简!

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char str[1010][50];
int m[50000000];
int match = 0;//记录组数
int Gcd(int a, int b)//求最大公约数
{
    int tep;
    if (a < b)
    {
        tep = a;
        a = b;
        b = tep;
    }
    if (b == 0)
    {
        return a;
    }
    return Gcd(b, a % b);
}
int main()
{
    int i, j;
    char in[30], ch, temp[30];
    int head = 0;
    int flag = 0;
    int count = 0;
    memset(in, 0, sizeof(in));
    memset(temp, 0, sizeof(temp));
    strcpy(temp, "BULLSHIT");
    while (scanf("%c", &ch) != EOF)
    {
        if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
        {
            in[head ++] = ch;//储存单词
        }
        else
        {
            if (head)//有单词的情况
            {
                in[head] = 0;
                count ++;//单词的个数
                strcpy(str[count], in);
                if (strcmp(in, temp) == 0)//一组的结束标志
                {
                    flag = 1;
                }
                memset(in, 0, sizeof(in));
                head = 0;//复位
            }
        }
        if (flag)//若一组结束
        {
            count --;//单词的个数
            flag = 0;//复位
            match ++;//一共的组数
            m[match] = count;
            for (i = 1; i <= count; i ++)
            {
                int len = strlen(str[i]);
                for (j = 0; j < len; j ++)
                {
                    if (str[i][j] >= 'a' && str[i][j] <= 'z')
                    {
                        str[i][j] += ('A' -'a');//统一换成小写字母
                    }
                }
            }
            for (i = 1; i < count; i ++)
            {
                for (j = i + 1; j <= count; j ++)
                {
                    if (strcmp(str[i], str[j]) == 0)//若匹配成功
                    {
                        m[match] --;
                        break;
                    }
                }
            }
            head = 0;//复位
            count = 0;
        }
    }
    if (head)//对最后的单词处理
    {
        in[head] = 0;
        count ++;
        strcpy(str[count], in);
        if (strcmp(str[count], temp) == 0)
        {
            flag = 1;
        }
        memset(in, 0, sizeof(in));
        head = 0;
    }
    if (flag)//若最后的单词是BULLSHIT
    {
        count --;
        flag = 0;
        match ++;//组数加一
        m[match] = count;
        for (i = 1; i < count; i ++)
        {
            for(j = i + 1; j <= count; j ++)
            {
                if (strcmp(str[i], str[j]) == 0)//匹配成功
                {
                    m[match] --;//匹配数减一
                    break;
                }
            }
        }
    }
    if (match)
    {
        int ans = 0;//记录总的个数
        for (i = 0; i <= match; i ++)
        {
            ans += m[i];
        }
        int gcd = Gcd(ans, match);//求出最大的公约数相当于约分
        ans = ans / gcd;
        match  = match / gcd;
        printf("%d / %d\n", ans, match);
    }
    else
    {
        printf("0 / 0\n");//特殊情况的时候总的组数为0也就是没有BULLSHIT这个标志
    }
    return 0;
}

 

 

posted on 2012-04-19 17:38  Stephen Li  阅读(405)  评论(0编辑  收藏  举报