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 1030202872 at 2010-08-01 16:01:45 on Problem 1159
为什么c++中主函数是void型就CE,用int型就AC呢?
CE代码
#include <iostream>
using namespace std;
short num[5010][5010];
char s1[5010],s2[5010];
void main()
{
 int len,i,j;
 cin>>len;
 for(i=1;i<=len;i++)
 {
	 cin>>s1[i];
     s2[len+1-i]=s1[i];
 }
 for(i=1;i<=len;i++)
	 for(j=1;j<=len;j++)
	 {
       if(s1[i]==s2[j])
        num[i][j]=num[i-1][j-1]+1;
	   else
		   num[i][j]=num[i-1][j]>num[i][j-1]?num[i-1][j]:num[i][j-1];
	 }
	cout<<len-num[len][len]<<endl;
}

AC代码
#include <iostream>
using namespace std;
short num[5010][5010];
char s1[5010],s2[5010];
int main()
{
 int len,i,j;
 cin>>len;
 for(i=1;i<=len;i++)
 {
	 cin>>s1[i];
     s2[len+1-i]=s1[i];
 }
 for(i=1;i<=len;i++)
	 for(j=1;j<=len;j++)
	 {
       if(s1[i]==s2[j])
        num[i][j]=num[i-1][j-1]+1;
	   else
		   num[i][j]=num[i-1][j]>num[i][j-1]?num[i-1][j]:num[i][j-1];
	 }
	cout<<len-num[len][len]<<endl;
	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