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 Liudonghua at 2009-04-23 23:53:24 on Problem 1159
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main(){
	string ch;
	vector<vector<int> > m;
	int n,h=0,max=0;
	cin>>n;
	if(n>50000 || n<3) exit(1);
	cin>>ch;
	if(ch.size()!=n) exit(1);
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(ch[i]==ch[j]){
				vector<int> temp(2,1);
				for(int k=i+1;k<=(i+j)/2;k++)
					if(ch[k]==ch[j-(k-i)] && k!=j-(k-i))  temp.front()++;
				temp.back()=j-i+1;
				m.push_back(temp);
				 
			}
		}
	}
	for(unsigned int i=0;i<m.size();i++){
		if(max<m[i][0]){
            max=m[i][0];
			h=m[i][1];
		}
	} 

    if(h%2==0) cout<<n-2*max<<endl;
    else cout<<n-2*max-1<<endl;
    system("pause");
	return 1;
}

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