pku2471.cpp
来自「这是ACM 方面的资料 是PKU的 北京大学的出来的」· C++ 代码 · 共 82 行
CPP
82 行
#include <stdio.h>
#include <string>
#include <cstring>
#include <set>
using namespace std;
typedef set<string> Word;
Word w;
int isChar(char c)
{
if (c >= 'a' && c <= 'z')
return 1;
if (c >= 'A' && c <= 'Z')
return 1;
return 0;
}
char toLower(char x)
{
return (x >= 'A' && x <= 'Z') ? x + 32 : x;
}
string getS()
{
char c;
string ans;
while (EOF != (c = getchar()) && !isChar(c));
if (EOF == c)
return "";
ans = ans + toLower(c);
while (EOF != (c = getchar()) && isChar(c))
{
ans = ans + toLower(c);
}
return c == EOF ? "" : ans;
}
int Gcd(int a, int b)
{
return b ? Gcd(b, a % b) : a;
}
int main()
{
string s;
int totalw, totalg;
int gcd;
totalw = 0;
totalg = 0;
int end = 0;
while (!end)
{
w.clear();
while (1)
{
s = getS();
if ("bullshit" == s)
break;
if (s.length() == 0)
{
end = 1;
break;
}
w.insert(s);
}
if (end)
{
break;
}
totalw += w.size();
totalg ++;
}
gcd = Gcd(totalw, totalg);
totalw /= gcd;
totalg /= gcd;
printf("%d / %d\n", totalw, totalg);
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?