Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

strncmp(), 用这个函数几行搞定,94ms

Posted by SCNU20152210056 at 2018-02-06 00:17:53 on Problem 1509
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

char str[20005];
int N;

void solve()
{
	int ans=0;
	for(int i=1;i<N;i++)
	{
		if(strncmp(str+ans,str+i,N)>0) ans=i;
	}
	printf("%d\n",ans+1);
}


int main()
{
#ifndef ONLINE_JUDGE
	freopen("data.in","r",stdin);
#endif
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%s",str);
		N=strlen(str);
		for(int i=0;i<N;i++)
			str[N+i]=str[i];
		solve();
	}	
} 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator