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

大牛帮帮忙,看看这种思路有没有错啊

Posted by wapian at 2010-08-16 11:27:40 on Problem 1159
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
int main()
{
	int i,j,k,m,n;
	char s[10000];
	scanf("%d",&n);
		scanf("%s",s);
	k=0;
	i=0;j=n-1;
	while(j>=i)
	{
		
		if(s[i]==s[j])
		{
			i++;
			j--;
		}
		else
		{
			if(s[i+1]==s[j]||s[i]==s[j-1])
			{
				if(s[i+1]==s[j])
				{
					k++;
					i++;
				}
			    if(s[i]==s[j-1])
				{
					k++;
					j--;
				}	
			}
				else
				{
					k+=2;
					i++;
					j--;	
				}
		}
	}
	printf("%d\n",k);
	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