U E D R , A S I H C RSS

[Lovely]boy^_^/USACO/Broken Necklace

  • ํ . —ญ‹œ „…˜ด € †’•„€‹ˆ ŠฌŠฌ •  Š”ตฐš” ;;
  • —ญ‹œ ํ•ด„ ‚ฝงˆกœ;; ดƒํ•œ ธธกœ  กŒ‹คŠ”;;
  • —ญ‹œ ํ…ŒŠคํŠธ งˆ‹ˆ ํ•ดด• ํ•œ‹คŠ” ˆ €ฆฌฒŒ Š‚€ ฌธ œ˜€‹คŠ”;;
  •  „ํ˜€ ƒฐ„ ชปํ•œ ฒฝšฐ€ ํŠ€–ด‚˜™€„œ ทธƒฐ ชปํ•ด€ฒŒ;;
  • ํ…ŒŠคํŠธ €ดŠค— งžถฐ ํ”„กœทธžจ ณ ณ‚˜€‹ค ณด‹ˆ..;;    ”Ÿฌ›ŒกŒ‹คŠ”;;
  • ชจฒ” ‹ต•ˆ€ ฒ‚˜ฒŒ ””ํ•˜˜ฐ..


~cpp 
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

ifstream fin("beads.in");
ofstream fout("beads.out");

int len = 0;
string BeadsList;

void InputData();
void OutputData();
int Process();
const string CutAndPasteBack(const string& str, int pos);

int main()
{
	InputData();

	fout << Process() << endl;

	fout.close();
	fin.close();

	return 0;
}

void InputData()
{
	fin >> len;
	fin >> BeadsList;
}

int Process()
{
	int lnum = 0;
	int rnum = 0;
	int max = 0;
	char cur;
	string temp;
	int i,j,curpos;
	bool allsame = false;

	for(i = 0 ; i < len ; ++i)
	{
		temp = CutAndPasteBack(BeadsList, i+1);

		cur = temp[0];
		if(cur == 'w')
		{
			for(j = 1 ; j < len ; ++j)
			{
				if(temp[j] != 'w')
				{
					cur = temp[j];
					break;
				}
			}
		}

		for(j = 0 ;; ++j)
		{
			if(cur == temp[j] || temp[j] == 'w')
				lnum++;
			else
			{
				curpos = j;
				break;
			}
		}

		if(j == len)
			allsame = true;

		if(!allsame)
		{
			cur = temp[len-1];
			if(cur == 'w')
			{
				for(j = 1 ; j < len ; ++j)
				{
					if(temp[len-1-j] != 'w')
					{
						cur = temp[len-1-j];
						break;
					}
				}
			}

			for(j = 0 ; j < len - curpos ; ++j)
			{
				if(cur == temp[len-1-j] || temp[len-1-j] == 'w')
					rnum++;
				else
					break;
			}
		}
		
		if(max < lnum + rnum)
		{
			max = lnum + rnum;
		}
		
		lnum = rnum = 0;
	}

	return max;	
}

const string CutAndPasteBack(const string& str, int pos)
{
	string front(str,0,pos-1);
	string back(str,pos-1,str.length());

	string ret = back+front;
	return ret;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:37
Processing time 0.0106 sec