Kattis-Alphabet Spam

题目所述基本内容

About 90 percent of the 300 billion emails sent every day are spam. Thus, a fast spam detection mechanism is crucial for large email providers. Lots of spammers try to circumvent spam detection by rewriting words like “M0n3y”, “Ca$h”, or “Lo||ery”.

A very simple and fast spam detection mechanism is based on the ratios between whitespace characters, lowercase letters, uppercase letters, and symbols. Symbols are defined as characters that do not fall in one of the first three groups.

输入输出样例

Input

The input consists of:

  • one line with a string consisting of at least 1 and at most 100000 characters.

A preprocessing step has already transformed all whitespace characters to underscores (_), and the line will consist solely of characters with ASCII codes between 33 and 126 (inclusive).

Output

Output four lines, containing the ratios of whitespace characters, lowercase letters, uppercase letters, and symbols (in that order). Your answer should have an absolute or relative error of at most 10−6.

代码

#include <iostream>
#include<string>
using namespace std;
int main()
{
    int i;
    string ch;
    cin >> ch;
    int len = ch.length();
    int Capital = 0, lowercase = 0, Symbol= 0, Underline = 0;
    for (i = 0; i <= len; i++) {
        if (ch[i] >= 'A' && ch[i] <= 'Z')
            Capital++;
        if (ch[i] >= 'a' && ch[i] <= 'z')
            lowercase++;
        if (ch[i] >= '!' && ch[i] <= '@')
            Symbol++;
        if (ch[i] >= '[' && ch[i] <= '^')
            Symbol++;
        if (ch[i] == '`')
            Symbol++;
        if (ch[i] >= '{' && ch[i] <= '~')
            Symbol++;
        if (ch[i] == '_')
            Underline++;
    }
    double wh, up, low, sy;
    double lenf = (double)len;
    wh =(double)Underline / lenf;
    up =(double)Capital / lenf;
    low =(double)lowercase / lenf;
    sy = (double)Symbol / lenf;
    printf("%.15lf\n", wh);
    printf("%.15lf\n", low);
    printf("%.15lf\n", up);
    printf("%.15lf\n", sy);
    return 0;
}

结束语

好兄弟好兄弟,留下你的关注和点赞,666走一波!!!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

做一个AC梦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值