TOPCODER_SRM566_DIV2_500

本文总结了一次编程比赛中因考虑不周导致的问题,并分享了具体的代码示例。通过一个字符串颜色匹配问题,展示了如何使用栈来解决类似问题,同时强调了细节处理的重要性。

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

这题考虑的不是很到位。导致比赛的时候错。。对于问题的考虑不够全面。哎。。就是少了一个=符号。。坑爹啊。。。

 

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
using namespace std;
stack<char> s;
int main()
{
	string colors;
	while(1)
	{
	//cin>>colors;
	int sum=0;
	while(!s.empty())s.pop();
	int len=colors.length();
    for(int i=0;i<len;i++)
    {
		if(s.empty())
		{s.push(colors[i]);continue;}
		if(s.top()==colors[i])
		{s.pop();sum++;}
		else
		s.push(colors[i]);
	}
	int ans=s.size();
	char topcolor=0;
	char endcolor=0;
	if(ans>0)
	{
	topcolor=s.top();
	endcolor=s.top();

	while(!s.empty())
	{
		endcolor=s.top();
		s.pop();
	}
	}
	int tog=ans/2;
	tog--;
	if(tog>0)sum+=tog;
	if(topcolor==endcolor && tog>=0)sum++;
	//cout<< sum<<endl;
	}
	
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值