为什么会WA呢?检查了一下没发现什么问题啊

P1184 高手之在一起

第一次,有了会做的题 还得到了检查无误的代码 两份喜悦相互重叠 这双重的喜悦又带来了更多更多的喜悦 本应已经得到了梦幻一般的AC时光 然而,为什么,会WA呢。。 (逃
by NaCly_Fish @ 2019-03-19 00:22:14


@[Watchman](/space/show?uid=177228) ```cpp #include<bits/stdc++.h> using namespace std; int main() { int n, m,kount=0; // cin >> n >> m; // scanf("\n"); scanf("%d %d\n",&n,&m); vector<string> gaoshou(n); vector<string> her(m); for (int i = 0; i < n; i++) { getline(cin,gaoshou[i]); while(!isalpha(gaoshou[i].back()))gaoshou[i].pop_back(); } for (int i = 0; i < m; i++) { getline(cin,her[i]); while(!isalpha(her[i].back()))her[i].pop_back(); } for (int i = 0; i < m; i++) { for(int j=0;j<n;j++) if (gaoshou[j] == her[i]) { kount++; break; } } cout << kount; //system("pause"); } ```
by Smile_Cindy @ 2019-03-19 10:00:16


@[Watchman](/space/show?uid=177228) 帮你改过了
by Smile_Cindy @ 2019-03-19 10:00:24


@[Alpha](/space/show?uid=87058) 十分感谢,请问为什么要用scanf()而不用cin呢?还有为什么一定要检查vector的最后一个元素呢?
by taoist610 @ 2019-03-19 12:41:14


@[Watchman](/space/show?uid=177228) 检查最后一个元素的原因是某些数据是在Windows条件下生成的,在Linux下使用getline会使某些字符串含有'\r'字符,而导致原本相等的串被认为不相等。 用scanf而不用cin的原因是scanf可以“吃掉”多余的空格和回车,而cin不能。
by Smile_Cindy @ 2019-03-19 18:14:34


|