求助为什么这题用getline80分改cin就ac了
查看原帖
求助为什么这题用getline80分改cin就ac了
569401
YYY955楼主2022/7/26 10:23
#include <bits/stdc++.h>
using namespace std;
const int P = 13331;
int main()
{
    int n;
    cin >> n;
    getchar();
    unordered_set<unsigned long long> cnt;
    for (int i = 0; i < n; i++)
    {
        unsigned long long h[10000] = {0}, p[10000] = {0};
        string a;
        getline(cin, a);
        h[0] = 0;
        p[0] = 1;
        for (int i = 0; i < a.size(); i++)
        {
            h[i + 1] = h[i] * P + a[i];
            p[i + 1] = p[i] * P;
        }
        cnt.insert(h[a.size()]);
    }
    cout << cnt.size();
    system("pause");
    return 0;
}
  ////这是80分的,wa了前两个点,但是数据我在本地和其他oi的自测都是过的
#include <bits/stdc++.h>
using namespace std;
const int P = 13331;
int main()
{
    int n;
    cin >> n;
    unordered_set<unsigned long long> cnt;
    for (int i = 0; i < n; i++)
    {
        unsigned long long h[10000] = {0}, p[10000] = {0};
        string a;
        cin >> a;
        h[0] = 0;
        p[0] = 1;
        for (int i = 0; i < a.size(); i++)
        {
            h[i + 1] = h[i] * P + a[i];
            p[i + 1] = p[i] * P;
        }
        cnt.insert(h[a.size()]);
    }
    cout << cnt.size();
    system("pause");
    return 0;
}
 //ac代码,只把getline改了cin
2022/7/26 10:23
加载中...