| ||||||||||
| 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 | |||||||||
关于Pascal的问题这里Pascal判输入结束是用eof吗?
为什么差不多的程序,一个Pascal,一个由P翻译到C++的程序,P的WA了,但是C++却AC了?
难道是因为eof的缘故?
求解答。
附代码:
Pascal:
var
sgv:array[0..200,0..200]of longint;
w,h:longint;
function sg(n,m:longint):longint;
var i,ans:longint;
bo:array[0..205]of boolean;
begin
if (sgv[n,m]>=0) then exit(sgv[n,m]);
fillchar(bo,sizeof(bo),0);
i:=2;
while (i<=n-i) do
begin
bo[sg(i,m) xor sg(n-i,m)]:=true;
inc(i);
end;
i:=2;
while (i<=m-i) do
begin
bo[sg(n,i) xor sg(n,m-i)]:=true;
inc(i);
end;
ans:=0;
while bo[ans] do inc(ans);
sgv[n,m]:=ans;
sgv[m,n]:=ans;
exit(sgv[n,m]);
end;
begin
fillchar(sgv,sizeof(sgv),255);
while not eof do
begin
read(w,h);
if (sg(w,h)<>0) then writeln('WIN')
else writeln('LOSE');
end;
end.
================================================================
C++:
#include <cstdio>
#include <cstring>
using namespace std;
int sgv[205][205];
int sg(int n, int m)
{
if (sgv[n][m] >= 0) return sgv[n][m];
bool bo[205];
memset(bo, 0, sizeof(bo));
int i;
for (i=2; i<=n-i; i++)
bo[sg(i,m) ^ sg (n-i,m)] = 1;
for (i=2; i<=m-i; i++)
bo[sg(n,i) ^ sg (n,m-i)] = 1;
for (i=0; bo[i]; i++);
return sgv[n][m] = sgv[m][n] = i;
}
int main()
{
int w,h;
memset(sgv, -1, sizeof(sgv));
while (scanf("%d%d", &w, &h) != EOF)
if (sg(w,h)) printf("WIN\n");
else printf("LOSE\n");
return 0;
}
(别问我为什么会C++还写Pascal,本蒟蒻是对于C++不太熟悉的NOIP选手。。。)
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator