tju3275Windy's S(最小表示法)

Xredman posted @ Apr 05, 2010 10:19:44 PM in Algorithm with tags tju 最小表示法 , 1208 阅读

//878303 	2010-04-06 08:54:36	Accepted 	3275	C++ 	0.5K	0'00.13" 	1456K
#include <iostream>
#include <string>
using namespace std;

int main()
{
	int T;
	string S;
	int i, j, k, len;
	cin>>T;
	while(T--)
	{
		cin>>S;
		len = S.length();
		S += S;
		i = 0; j = 1;
		while(i < len && j < len)
		{
			k = 0; 
			while(k < len && S[i + k] == S[j + k])
				k++;
			if(k >= len)
				break;
			if(S[i + k] > S[j + k])
				i= max(i + k + 1, j + 1);
			else
				j = max(i + 1, j + k + 1);
		}
		i = min(i, j);
		for(k = 0; k < len; k++)
			cout<<S[i + k];
		cout<<endl;
	}
	return 0;
}

 

 






Uttarakhand Intermed 说:
Sep 01, 2023 11:45:47 PM

Uttarakhand Board Of School Education (UBSE) Responsible For Conducting 12th Class Examination Starting Month of April 2024, Students Download UBSE 12th Class Model Paper 2024 at Official Website Only, Uttarakhand Intermediate Model Paper 2024 Intermediate Students across Uttarakhand Board are advised to Visit this Board page on Regular basis to get their Uttarakhand Board 12th Class Question Paper 2024. Provide UK Board 12th Class Latest and Last Year Exam Study Material for Syllabus, Question Paper etc, Hindi, English Medium Pdf Format, Uttarakhand Intermediate is a very Crucial year for the Students, as their Passing marks in the year will Determine their Educational Career ahead.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter