zoukankan      html  css  js  c++  java
  • 【PAT甲级】1071 Speech Patterns (25 分)(getline(cin,x))

    题意:

    输入一行字符串,输出出现过次数最多的由字母和数字组成的字符串以及它出现的次数(对大小写不敏感,输出全部输出小写)。

    AAAAAccepted code:

     1 #define HAVE_STRUCT_TIMESPEC
     2 #include<bits/stdc++.h>
     3 using namespace std;
     4 string word;
     5 map<string,int>mp;
     6 string s;
     7 int main(){
     8     ios::sync_with_stdio(false);
     9     cin.tie(NULL);
    10     cout.tie(NULL);
    11     string x;
    12     getline(cin,x);
    13     int n=x.size();
    14     for(int i=0;i<n;++i)
    15         if((x[i]>='A'&&x[i]<='Z')||(x[i]>='a'&&x[i]<='z')||(x[i]>='0'&&x[i]<='9')){
    16             if(x[i]>='A'&&x[i]<='Z')
    17                 x[i]=x[i]-'A'+'a';
    18             word.push_back(x[i]);
    19         }
    20         else if(word!=""){
    21             ++mp[word];
    22             word.clear();
    23         }
    24     if(word!=""){
    25         ++mp[word];
    26         word.clear();
    27     }
    28     int mx=0;
    29     for(auto it:mp)
    30         if(it.second>mx){
    31             mx=it.second;
    32             s=it.first;
    33         }
    34     cout<<s<<" "<<mx;
    35     return 0;
    36 }
    保持热爱 不懈努力 不试试看怎么知道会失败呢(划掉) 世上无难事 只要肯放弃(划掉)
  • 相关阅读:
    v-date
    文字在图片上
    v-生命周期
    彭博接口分类
    如何指定vim 的查找是从上往下还是从下往上[z]
    查看linux版本
    git web找不到new project解决方法
    比特币运行原理[z]
    [Z]haproxy+keepalived高可用群集
    blockchain good article
  • 原文地址:https://www.cnblogs.com/ldudxy/p/11796091.html
Copyright © 2011-2022 走看看