PAT甲1071 Speech Patterns(25 分)

由于给定内容为空,无法提取关键信息生成摘要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <map>
using namespace std;

map<string,int> mp;

bool isc(char a)
{
    if(a>='a'&&a<='z')return true;
    else if(a>='A'&&a<='Z')return true;
    else if(a>='0'&&a<='9')return true;
    else return false;
}

void tolower(string &str)
{
    for(int i=0;i<str.length();i++)
    {
        if(str[i]>='A'&&str[i]<='Z')
        {
            str[i]=str[i]-'A'+'a';
        }
    }
}


string maxstr;
int maxn=-1;
void split(string str)
{
    string temp="";
    int index=0;
    int pre=0;
    while(index<str.length())
    {
        if(!isc(str[index])&&index==pre)
        {
            pre++;
            index++;
        }
        else if(!isc(str[index])&&index>pre)
        {
            temp=str.substr(pre,index-pre);
            tolower(temp);
            if(mp.find(temp)==mp.end())
            {
                mp[temp]=0;
            }
            mp[temp]++;
            index++;
            pre=index;
            if(mp[temp]>=maxn)
            {
                if(mp[temp]>maxn)
                {
                    maxn=mp[temp];
                    maxstr=temp;
                }
                else if(temp<maxstr)
                {
                    maxstr=temp;
                }
            }
        }
        else if(isc(str[index])&&index<str.length()-1)
        {
            index++;
        }
        else if(isc(str[index])&&index==str.length()-1)
        {
            temp=str.substr(pre,index-pre+1);
            tolower(temp);
            if(mp.find(temp)==mp.end())
            {
                mp[temp]=0;
            }
            mp[temp]++;
            index++;
            pre=index;
            if(mp[temp]>=maxn)
            {
                if(mp[temp]>maxn)
                {
                    maxn=mp[temp];
                    maxstr=temp;
                }
                else if(temp<maxstr)
                {
                    maxstr=temp;
                }
            }
        }
    }
}



int main()
{
    string str;
    getline(cin,str);
    split(str);
    cout<<maxstr<<" "<<maxn<<endl;
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值