AtCoder Beginner Contest 329

C - Count xxx

题意是:给你一个字符串,求出字符串里面相同字母的子串数量

思路:用map映射即可,取每个字母的最大长度,然后加起来

using namespace std;
int main(){
	int n;
	string s;
	cin>>n>>s;
	map<char,int>mp;
	int ct=1;
	for(int i=1;i<n;i++){
		if(s[i]!=s[i-1]){
			mp[s[i-1]]=max(mp[s[i-1]],ct);
			ct=1;
		}else{
			ct++;
		}
	}
	mp[s[n-1]]=max(mp[s[n-1]],ct);
	int ans=0;
	for(auto c:mp){
		ans+=c.second;
	}
	cout<<ans;
	return 0;
} 

D - Election Quick Report

题意是:进行一个选举,n个人m次投票,每投票一次就打印出票最多的人

using namespace std;
const int N=2e5+10;
int a[N];
int main(){
	int n,m;
	cin>>n>>m;
	int t;
	cin>>t;
	cout<<t<<"\n";
	a[t]++;
	queue<int>q;
	q.push(t);
	for(int i=2;i<=m;i++){
		int x;
		cin>>x;
		a[x]++;
		if(a[x]>a[q.front()]&&x!=q.front()||(a[x]==a[q.front()]&&x<q.front())){
			q.pop();
			q.push(x);
		}
		cout<<q.front()<<"\n";
	}
	return 0;
}

本文作者:yufan1102

本文链接:https://www.cnblogs.com/yufan1102/p/17846387.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   yufan1102  阅读(25)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.