数据中间可能有空格吧
by ICU152_QWQ_IS8 @ 2023-10-22 01:13:18
输入 $a_i$ 和 $b_i$ 混了改为
```cpp
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int j=0;j<m;j++)
{
cin>>b[j];
}
for(int j=0;j<m;j++)
{
if(b[j]==a[i])
{
ans++;
break;
}
}
```
另外题目说了 ```地名中可能有空格。```把 ```cin``` 改成 ```getline(cin,);```
完整代码
```cpp
//洛谷题_P1184_高手之在一起
#include<bits/stdc++.h>
#pragma /*GCC*/G++ optimize(1)
#pragma /*GCC*/G++ optimize(2)
#pragma /*GCC*/G++ optimize(3)
using namespace std;
long long n=0,m=0,sum=0;
string s[21]={},t;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("P1184.in","r",stdin);
//freopen("P1184.out","w",stdout);
cin>>n>>m;
getline(cin,s[1]);
for(int i=1;i<=n;i++){
getline(cin,s[i]);
}
while(m--){
getline(cin,t);
for(int i=1;i<=n;i++){
if(t==s[i]){
sum++;
break;
}
}
}
cout<<sum;
return 0;
}
```
by han_jian__wu_wei_han @ 2023-10-22 07:40:58
神马情况,调完后样例都过不了
```cpp
#include<bits/stdc++.h>
using namespace std;
long long n,m,ans=0;
string a[25],b[1000005];
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
{
getline(cin,a[i]);
}
for(int j=0;j<m;j++)
{
getline(cin,b[j]);
}
for(int j=0;j<m;j++)
{
for(int i=0;i<n;i++)
{
if(b[j]==a[i])
{
ans++;
break;
}
}
}
cout<<ans;
return 0;
}
```
by shooting__star @ 2023-10-22 09:53:33
那就是洛谷的问题(doge)
by ZYK_beishetianlang @ 2023-10-22 09:55:24
能不能正常点,当心我举报
by shooting__star @ 2023-10-22 09:56:52
@[shooting__star](/user/955954) getline之前药要加上getchar
by hexuchen @ 2023-10-22 11:42:21
@[hexuchen](/user/945742) ?
by shooting__star @ 2023-10-22 11:44:04
@[shooting__star](/user/955954)
```cpp
#include<bits/stdc++.h>
using namespace std;
long long n,m,ans=0;
string a[25],b[1000005];
int main()
{
cin>>n>>m;
getchar();//过滤掉换行
for(int i=0;i<n;i++)
{
getline(cin,a[i]);
}
for(int j=0;j<m;j++)
{
getline(cin,b[j]);
}
for(int j=0;j<m;j++)
{
for(int i=0;i<n;i++)
{
if(b[j]==a[i])
{
ans++;
break;
}
}
}
cout<<ans;
return 0;
}
```
by hexuchen @ 2023-10-22 11:44:47
@[shooting__star](/user/955954) cin后面的getline读入的是换行,要加getchar过滤换行
by hexuchen @ 2023-10-22 11:45:47