求助,为什么提交上去显示的答案和我自己测试的不一样?

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

第一个就WA了,答案是GO但我的是STAY,但是我自己用dev和VS测第一个测试数据测得的都是GO,不知道自己哪里有问题
by shiiki @ 2022-12-22 19:42:37


建议拿洛谷 IDE 测一下。
by wbs200 @ 2022-12-22 19:53:09


改成string好像就好了
by guohanxing @ 2022-12-22 19:57:25


遍历循环即可 ``` #include <bits/stdc++.h>//万能头文件,建议背下来,可以减少编译时间,防止超时 using namespace std; int charToInt1200(char ch) { return ch - 0x40; } int convertToInt(string name) { int sum = 1; for (int i = 0; i < name.length(); i++) sum *= charToInt1200(name[i]); return sum % 47; } int main() { string nameMeteor, nameTeam; cin >> nameMeteor >> nameTeam; if (convertToInt(nameMeteor) == convertToInt(nameTeam)) cout << "GO" << endl; else cout << "STAY" << endl; return 0; } ```
by I_love_ZXY @ 2022-12-22 20:24:16


@[My_God](/user/914658) 奇怪了,你的代码怎么跟[第五篇题解](https://www.luogu.com.cn/blog/user36787/solution-p1200) 一样啊。 还翻了下您的提交记录,黑题都是抄的吧。
by FQR_ @ 2022-12-22 20:41:01


将fgets改成scanf可以通过,我由自己的尝试得出应该是在用fgets时导致的错误的结果。 对于本地IDE中的 ```c fgets(z1,8,stdin); fgets(z2,8,stdin); ``` 这一段,在洛谷IDE中应该改为 ```c fgets(z1,9,stdin); fgets(z2,9,stdin); ``` 才能使在输入形如 ABCDEF ABCDE 这类第一行字符串长度为6的数据时 本地与洛谷IDE的每个`z[i]-'0'-16`的值相同 且如果尝试在洛谷IDE中用 ```c fgets(z1,8,stdin); fgets(z2,8,stdin); ``` 程序好像会把ABCDEF末尾的 \n 输入到z2中,我是初学者,具体原因我也不太清楚,希望能有大佬来解答一下
by shiiki @ 2022-12-22 21:35:32


|