为什么错了?求大神 在我的Dev和VS运行结果和答案一样

P1200 [USACO1.1] 你的飞碟在这儿 Your Ride Is Here

和官方答案一模一样,但是oj判错,多半是输入的问题。 你不要用%n,直接用strlen读取字符串长度试试。
by xiaotongtong @ 2020-02-21 00:30:27


c++路过 ~~这是c吗?~~
by DOs__lx @ 2020-02-21 08:17:14


@[q1321337557](/user/319240) 你在洛谷的在线IDE试过了吗
by 屑稻香 @ 2020-02-21 08:23:25


码风真的…… ```cpp #include<stdio.h> int main() { int i,cnt=0,Scnt=0,sum=1,Ssum=1; char comet[7],row[7]; scanf("%s%n", comet,&cnt); scanf("%s%n", row,&Scnt); for (i = 0; i < cnt; i++) sum *= (comet[i] - 64); for (i = 0; i < Scnt-1; i++) Ssum *= (row[i] - 64); if ((sum %= 47) == (Ssum %= 47)) printf("GO"); else printf("STAY"); return 0; } ```
by OvOAuto @ 2020-02-21 08:29:21


@[xiaotongtong](/user/310205) 用strlen过了,但是这个%n为什么出问题了
by q1321337557 @ 2020-02-21 08:41:56


@[windowswu](/user/320656) 试过了昂- -
by q1321337557 @ 2020-02-21 08:42:32


@[q1321337557](/user/319240) 呃,其实我也不太清楚,只是刚好我之前也遇到这种问题并用相同的办法解决了。 个人认为是oj是以文件的形式读入,而代码用%n这种特殊的形式获取输入字符串长度,干扰了文件读入。你可以把代码也改成文件的形式读入对比一下输出。
by xiaotongtong @ 2020-02-21 11:23:09


|