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.0082 sec