求解为什么样例过不了
查看原帖
求解为什么样例过不了
532067
rochcim楼主2021/11/14 10:22
#include <iostream>
#include <string>
#include <vector>
#define MAXN 1510
#define base 261
#define mod 10007
using namespace std;
int n, ans = 0;
char s[MAXN];
vector <string> linker[mod + 2];
inline void insert(string s) {
    int hash;
    int m = s.length();
    for (int i = 0; i < m; i++)
        hash = (hash * base + s[i]) % mod;
    for (int i = 0; i < linker[hash].size(); i++) {
        if (linker[hash][i] == s)
            return;
        linker[hash].push_back(s);
        ans++;
    }
}
int main () {
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> s;
        insert(s);
    cout << ans << endl;
    return 0;
}
基本照抄深基教材,但样例显示0??
求帮看,谢谢!!
2021/11/14 10:22
加载中...