zoukankan      html  css  js  c++  java
  • PATA 1071 Speech Patterns.

    #include <bits/stdc++.h>
    using namespace std;
    bool check(char c)//检查是否为字母或数字
    {
    	if(c>='A'&&c<='Z'||c>='a'&&c<='z'||c>='0'&&c<='9') 
    		return true;
    	else
    		return false;
    } 
    int main()
    {
    	map<string,int> count;
    	string str;
    	getline(cin,str);
    	int i = 0;
    	while(i<str.length())
    	{
    		string word;
    		while(i<str.length()&&check(str[i]))
    		{
    			if(str[i]>='A'&&str[i]<='Z'){  //大写统一改为小写
    				str[i] += ('a'-'A');
    			}
    			word += str[i]; //字符拼接 +
    			i++;
    		}		
    		if(word != ""){
    			if(count.find(word)==count.end())	count[word]=1;  //这单词还没出现过,计数为1
    			else count[word]++;
    		}
    		while(i<str.length()&&!check(str[i]))  //遇到其它字符跳过
    		{
    			i++;
    		}
    	}
    	string ans;
    	int  MAX=0;
    	for(map<string,int>::iterator it=count.begin();it != count.end();it++)  //只能用!=,而不能用<end() 
    	{
    		if(it->second>MAX)
    		{
    			ans = it->first;
    			MAX = it->second;
    		}
    	}
    	cout<<ans<<" "<<MAX<<endl;
    	return 0;
    	
    	
    }
    

      

  • 相关阅读:
    Valid Parentheses
    3Sum
    泛型(一)
    Longest Common Prefix
    Roman to Integer
    Integer to Roman
    Container With Most Water
    知道创宇研发技能表v2.2
    anti-dns pinning 攻击
    dominator
  • 原文地址:https://www.cnblogs.com/qiangz/p/8552382.html
Copyright © 2011-2022 走看看