PAT 1071【STL string应用】
2017-03-21 22:50
357 查看
1.单case很多清空没必要的
2.string+ char 最好用pushback
3.string +string就直接+
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e6+10;
map<string, int> mp;
string temp,res;
int num;
string s;
int n;
bool Judge(char x)
{
if(x>='0'&&x<='9') return true;
if(x>='A'&&x<='Z') return true;
if(x>='a'&&x<='z') return true;
return false;
}
int main()
{
getline(cin,s);
n=s.length();
bool flag = true;
int ans=0;
//mp.clear();
temp = "";
for(int i=0;i<n;i++)
{
if(s[i]>='A'&&s[i]<='Z')
s[i] = s[i] + 'a' - 'A';
if(Judge(s[i]))
{
temp.push_back(s[i]);//temp = temp + s[i];
flag=true;
}
else
{
num = temp.length();
if(num)
{
mp[temp]++;
if(mp[temp]>ans)
{
ans = mp[temp];
res = temp;
}
temp = "";
flag = false;
}
}
}
if(flag)
{
mp[temp]++;
if(mp[temp]>ans)
{
ans = mp[temp];
res = temp;
}
}
cout<<res<<" "<<ans<<endl;
return 0;
}
2.string+ char 最好用pushback
3.string +string就直接+
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e6+10;
map<string, int> mp;
string temp,res;
int num;
string s;
int n;
bool Judge(char x)
{
if(x>='0'&&x<='9') return true;
if(x>='A'&&x<='Z') return true;
if(x>='a'&&x<='z') return true;
return false;
}
int main()
{
getline(cin,s);
n=s.length();
bool flag = true;
int ans=0;
//mp.clear();
temp = "";
for(int i=0;i<n;i++)
{
if(s[i]>='A'&&s[i]<='Z')
s[i] = s[i] + 'a' - 'A';
if(Judge(s[i]))
{
temp.push_back(s[i]);//temp = temp + s[i];
flag=true;
}
else
{
num = temp.length();
if(num)
{
mp[temp]++;
if(mp[temp]>ans)
{
ans = mp[temp];
res = temp;
}
temp = "";
flag = false;
}
}
}
if(flag)
{
mp[temp]++;
if(mp[temp]>ans)
{
ans = mp[temp];
res = temp;
}
}
cout<<res<<" "<<ans<<endl;
return 0;
}
相关文章推荐
- UVA 10815 Andy's First Dictionary 安迪的字典 stl应用 set+string做法
- USACO Palindromic Squares 【STL__string_的应用】
- 集训final D STL中string的应用
- PAT QQ帐户的申请与登陆 STL-MAP的应用
- 擅长排列的小明 string(stl)的应用 + 排列
- PAT - 甲级 - 1071. Speech Patterns (25)(STL-map)
- STL-PAT-A1100 & B.1044 [string & map]
- hdu 1894 String Compare 还蛮不错的题目 STL 中的string应用
- stl string 简单应用
- 详细解说STL string
- stringgrid 应用例子
- stl应用小问题
- Java基本的API中,String,StringBuffer,Math,Wapper class的基本应用
- 在Asp.Net 2.0中应用DataFormatString
- Spring bean配置中属性值由String到实际类型的动态转化过程及PropertyEditor类的应用
- (原創) 如何將std::string轉成大寫(小寫)? (C/C++) (STL) (C)
- 详细解说STL string
- Java基本的API中,String,StringBuffer,Math,Wapper class的基本应用
- xstring(继承了stl的string)
- 18函数对象&19command模式20函数对象在STL中的应用