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

状告POJ这个程序虽然是暴力但思维有漏洞我自杀,过了所有数据!!!!!!

Posted by ShenZhiBM at 2010-07-16 09:32:02 on Problem 1509
#include <iostream>
#include <algorithm>
using namespace std;
char c[10010],len;
int cmp(int a,int b)
{
	int i=a,j=b;
	do
	{
		if(c[i]>c[j])return 1;
		else if(c[j]>c[i])return 2;
		i++;
		j++;
		i=i%len;
		j=j%len;
	}
	while(i%len!=a&&j%len!=b);
	return 0;
}
int main()
{
	int n,i,j;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%s",c);
		len=strlen(c);
		int max=0;
		for(i=1;i<len;i++)
		{
			if(cmp(i,max)==2)max=i;
		}
		printf("%d\n",max+1);
	}
	return 0;
}

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