字符区分读入。分数化简。HOJ2046 Bullshit Bingo。

简单题。在输入的text段中提取只有字母的单词。(效率不高)

求最大公约数化简。

Bullshit Bingo


Time limit:1sec.Submitted:99
Memory limit:32MAccepted:46
Source: University of Ulm Internal Contest 2005

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 file 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

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

说明:

读取只有字母的单词。遇到一个BULLSHIT统计一下之前出现的不同的词有多少。这些词大小写不敏感。

最后输出 不同的词总数(每次游戏单独计算后相加) / 游戏数(即BULLSHIT数) 的最简分数形式。

stl set存词。每次游戏结束时清空一次。set.size()即为不同的词数。

代码如下:

 
  
#include < iostream >
#include
< stdio.h >
#include
< set >
using namespace std;

void sim( int & m, int & n) {
int x = m, y = n;
if (x < y)swap(x, y);
int r = x % y;
while (r != 0 ) {
x
= y;
y
= r;
r
= x % y;
}
m
/= y, n /= y;
}

int main() {
set < string > m;
string tmp = "" ;
char ch;
int sum = 0 , sumg = 0 ;
while ((ch = getchar()) != EOF) {
if (ch >= ' a ' && ch <= ' z ' || ch >= ' A ' && ch <= ' Z ' )
tmp
+= ch;
else if ( ! tmp.empty()) {
if (tmp == " BULLSHIT " ) {
sumg
++ ;
sum
+= m.size();
m.clear();
}
else {
for ( int i = 0 ; i < tmp.length(); i ++ )
if (tmp[i] <= ' Z ' )tmp[i] += 32 ;
m.insert(tmp);
}
tmp.clear();
}
}
if (tmp == " BULLSHIT " ) {
sumg
++ ;
sum
+= m.size();
}
sim(sum, sumg);
cout
<< sum << " / " << sumg << endl;
return 0 ;
}

转载于:https://www.cnblogs.com/yangchenhao8/archive/2011/06/10/2078023.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值