zoukankan      html  css  js  c++  java
  • 1071. Speech Patterns (25)

    People often have a preference among synonyms of the same word. For example, some may prefer "the police", while others may prefer "the cops". Analyzing such patterns can help to narrow down a speaker's identity, which is useful when validating, for example, whether it's still the same person behind an online avatar.

    Now given a paragraph of text sampled from someone's speech, can you find the person's most commonly used word?

    Input Specification:

    Each input file contains one test case. For each case, there is one line of text no more than 1048576 characters in length, terminated by a carriage return ' '. The input contains at least one alphanumerical character, i.e., one character from the set [0-9 A-Z a-z].

    Output Specification:

    For each test case, print in one line the most commonly occurring word in the input text, followed by a space and the number of times it has occurred in the input. If there are more than one such words, print the lexicographically smallest one. The word should be printed in all lower case. Here a "word" is defined as a continuous sequence of alphanumerical characters separated by non-alphanumerical characters or the line beginning/end.

    Note that words are case insensitive.

    Sample Input:
    Can1: "Can a can can a can?  It can!"
    
    Sample Output:
    can 5
    
    代码:
    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <map>
    using namespace std;
    
    int main()
    {
        char ch,str[10];
        map<string,int> p;
        string s;
        int i = 0,j,m = 0;
        do
        {
            ch = getchar();
            if(isalnum(ch))
            {
                if(isupper(ch))
                {
                    str[i ++] = ch + 32;
                }
                else str[i ++] = ch;
            }
            else if(i != 0)
            {
                str[i] = '';
                i = 0;
                p[str] ++;
                if(m < p[str])m = p[str],s = str;
                else if(m == p[str] && s > str)s = str;
            }
        }
        while(ch != '
    ');
        cout<<s<<' '<<m;
    }
  • 相关阅读:
    kali更新源
    中国Linux源镜像站大全
    火狐浏览器Firefox上DownThemAll插件
    使用 backdoor 工具注入ShellCode
    动态加载 ShellCode绕过杀软
    渗透测试的本质与沉思
    Payload 实现分离免杀
    XSS跨站攻击靶场-通关笔记
    Web文件上传靶场
    Python 常用外部模块详解
  • 原文地址:https://www.cnblogs.com/8023spz/p/8214977.html
Copyright © 2011-2022 走看看