Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
??????????????为什么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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator